Module: TextMagic::API::Charset

Included in:
TextMagic::API
Defined in:
lib/textmagic/charset.rb

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#gsm?(text) ⇒ Boolean Also known as: is_gsm

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

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/textmagic/charset.rb', line 14

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

#real_length(text, unicode) ⇒ Object



27
28
29
# File 'lib/textmagic/charset.rb', line 27

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

#unicode?(text) ⇒ Boolean Also known as: is_unicode

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

Returns:

  • (Boolean)


22
23
24
# File 'lib/textmagic/charset.rb', line 22

def unicode?(text)
  !is_gsm(text)
end