Class: Smshelper::Languagetools::Charset

Inherits:
Object
  • Object
show all
Defined in:
lib/smshelper/languagetools/languagetools.rb

Constant Summary collapse

GSM_CHARSET =
"@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\e\f^{}\\[~]|€ÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà".scan(/./u)
ESCAPED_CHARS =
"{}\\~[]|€"

Instance Method Summary collapse

Instance Method Details

#is_gsm(text) ⇒ Object

Returns true if the supplied text contains only characters from GSM 03.38 charset, otherwise it returns false.



38
39
40
41
# File 'lib/smshelper/languagetools/languagetools.rb', line 38

def is_gsm(text)
  text.scan(/./u).each { |c| return false unless GSM_CHARSET.include?(c) }
  true
end

#is_unicode(text) ⇒ Object

Returns true if the supplied text contains characters outside of GSM 03.38 charset, otherwise it returns false.



45
46
47
# File 'lib/smshelper/languagetools/languagetools.rb', line 45

def is_unicode(text)
  !is_gsm(text)
end

#real_length(text, unicode) ⇒ Object



49
50
51
# File 'lib/smshelper/languagetools/languagetools.rb', line 49

def real_length(text, unicode)
  text.size + (unicode ? 0 : text.scan(/[\{\}\\~\[\]\|€]/).size)
end