module Smess
Constants
- SMS_MAX_LENGTH
- VERSION
Public Class Methods
booleanize(value)
click to toggle source
# File lib/smess/utils.rb, line 6 def booleanize(value) value.to_s.downcase == "true" end
config()
click to toggle source
# File lib/smess.rb, line 43 def self.config @config ||= Config.new end
configure() { |config| ... }
click to toggle source
# File lib/smess.rb, line 51 def self.configure yield(config) end
named_output_instance(name)
click to toggle source
# File lib/smess.rb, line 37 def self.named_output_instance(name) output_class_name = config.configured_outputs.fetch(name)[:type].to_s.camelize conf = config.configured_outputs[name][:config] "Smess::#{output_class_name}".constantize.new(conf) end
new(*args)
click to toggle source
# File lib/smess.rb, line 33 def self.new(*args) Sms.new(*args) end
reset_config()
click to toggle source
# File lib/smess.rb, line 47 def self.reset_config @config = Config.new end
separate_sms(text)
click to toggle source
returns an array of strings of <160 char lengths, split on whitespace this should be used when sending via non-concatenating providers
# File lib/smess/utils.rb, line 34 def separate_sms(text) return [text] unless text.sms_length > SMS_MAX_LENGTH result = [] while text.sms_length > SMS_MAX_LENGTH part, text = text.split_at( separation_point(text) ) result << part.strip end result << text.strip end
split_sms(text)
click to toggle source
returns an array of strings of gsm-compatible lengths this should be used when sending via concatenating providers
# File lib/smess/utils.rb, line 12 def split_sms(text) return [text] unless text.sms_length > 160 result = [] while text.sms_length > 0 part, text = text.split_at( split_point(text) ) result << part end result end
Private Class Methods
separation_point(text)
click to toggle source
This is used when there is no concatenation and you want the string split on whitespace.
# File lib/smess/utils.rb, line 63 def separation_point(text) end_char = SMS_MAX_LENGTH + 1 while text.sms_length > SMS_MAX_LENGTH || !(text[-1] =~ /\s/) end_char -= 1 text = text.split_at(end_char).first end end_char end
split_point(text)
click to toggle source
for finding the GSM alphabet split point for concatenated message strings The reason this is a bit qirky is that a subset of characters are “extended”. These and take 2 bytes and the number of these in the message body alter the “byte” splitpoint.
# File lib/smess/utils.rb, line 52 def split_point(text) end_char = 155 while text.sms_length > 154 end_char -= 1 text = text.split_at(end_char).first # puts "split_point #{end_char}" end end_char end