Module: Jung::Drivers::Infobip::SmsCounter
- Defined in:
- lib/jung/drivers/infobip/sms_counter.rb
Class Method Summary collapse
Class Method Details
.count(text) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/jung/drivers/infobip/sms_counter.rb', line 26 def self.count(text) encoding = detectEncoding(text) length = text.length length += countGsm7bitEx(text) if encoding == :gsm_7bit_ex = @messageLength[encoding] = @multiMessageLength[encoding] if length > = (length.to_f / ).ceil remaining = ( * ) - length { :encoding => encoding, :length => length, :per_message => , :remaining => remaining, :messages => } end |
.countGsm7bitEx(text) ⇒ Object
55 56 57 58 |
# File 'lib/jung/drivers/infobip/sms_counter.rb', line 55 def self.countGsm7bitEx(text) chars = text.each_char.select {|char| char.match(@gsm7bitExOnlyRegExp) } chars.size end |
.detectEncoding(text) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/jung/drivers/infobip/sms_counter.rb', line 47 def self.detectEncoding(text) case when text.match(@gsm7bitRegExp) then :gsm_7bit when text.match(@gsm7bitExRegExp) then :gsm_7bit_ex else :utf16 end end |