Module: Ovh::Http2sms::GsmEncoding
- Defined in:
- lib/ovh/http2sms/gsm_encoding.rb
Overview
GSM 03.38 encoding utilities for SMS character counting
Uses the gsm_encoder gem for character validation and provides OVH-specific SMS limits accounting for the STOP clause.
Standard SMS messages use GSM 7-bit encoding which allows 160 characters. Extension characters (€, |, ^, {, }, [, ], ~, ) count as 2 characters. Non-GSM characters force Unicode encoding which limits messages to 70 characters.
Commercial SMS must include STOP clause which uses 11 characters, reducing the first SMS limit.
Constant Summary collapse
- GSM_SINGLE_SMS_LIMIT =
SMS limits for GSM 7-bit encoding
160- GSM_CONCAT_SMS_LIMIT =
7 chars used for UDH header in concatenated SMS
153- GSM_FIRST_COMMERCIAL_LIMIT =
After STOP clause (11 chars)
149- GSM_CONCAT_COMMERCIAL_LIMIT =
153- UNICODE_SINGLE_SMS_LIMIT =
SMS limits for Unicode encoding
70- UNICODE_CONCAT_SMS_LIMIT =
3 chars used for UDH header
67- UNICODE_FIRST_COMMERCIAL_LIMIT =
After STOP clause (11 chars)
59- UNICODE_CONCAT_COMMERCIAL_LIMIT =
70- EXTENSION_CHARACTERS =
Extension characters that count as 2 in GSM encoding
Set["€", "|", "^", "{", "}", "[", "]", "~", "\\"].freeze
Class Method Summary collapse
-
.detect_encoding(message) ⇒ Symbol
Detect the required encoding for a message.
-
.gsm_char_count(message) ⇒ Integer
Calculate the GSM character count (extension chars count as 2).
-
.gsm_compatible?(message) ⇒ Boolean
Check if a message contains only GSM 03.38 characters.
-
.message_info(message, commercial: true) ⇒ Hash
Calculate message info including SMS count.
-
.non_gsm_characters(message) ⇒ Array<String>
Find all non-GSM characters in a message.
Class Method Details
.detect_encoding(message) ⇒ Symbol
Detect the required encoding for a message
55 56 57 |
# File 'lib/ovh/http2sms/gsm_encoding.rb', line 55 def detect_encoding() gsm_compatible?() ? :gsm : :unicode end |
.gsm_char_count(message) ⇒ Integer
Calculate the GSM character count (extension chars count as 2)
67 68 69 70 71 |
# File 'lib/ovh/http2sms/gsm_encoding.rb', line 67 def gsm_char_count() .each_char.sum do |char| EXTENSION_CHARACTERS.include?(char) ? 2 : 1 end end |
.gsm_compatible?(message) ⇒ Boolean
Check if a message contains only GSM 03.38 characters
43 44 45 |
# File 'lib/ovh/http2sms/gsm_encoding.rb', line 43 def gsm_compatible?() GSMEncoder.can_encode?() end |
.message_info(message, commercial: true) ⇒ Hash
Calculate message info including SMS count
99 100 101 102 103 104 105 106 107 |
# File 'lib/ovh/http2sms/gsm_encoding.rb', line 99 def (, commercial: true) encoding = detect_encoding() if encoding == :gsm (, commercial: commercial) else (, commercial: commercial) end end |
.non_gsm_characters(message) ⇒ Array<String>
Find all non-GSM characters in a message
80 81 82 |
# File 'lib/ovh/http2sms/gsm_encoding.rb', line 80 def non_gsm_characters() .each_char.reject { |char| can_encode_char?(char) }.uniq end |