Class: SMSApi::Validators::MessageBodyValidator
- Inherits:
-
Object
- Object
- SMSApi::Validators::MessageBodyValidator
- Defined in:
- lib/client_smsapi/validators/message_body_validator.rb
Constant Summary collapse
- DOUBLE_COST_CHARS =
"\"^{}[]~\\|€\n".freeze
- BASIC_CHARS =
"\n\f\r !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{|}~ ¡£¤¥§¿ÄÅÆÉÑÖØÜßàäåæçèéìñòöøùüΓΔΘΛΞΠΣΦΨΩ€".freeze
- BASIC_LIMIT =
918
- EXTRA_LIMIT =
402
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Class Method Summary collapse
Instance Method Summary collapse
- #basic_charset? ⇒ Boolean
- #body_codepoints ⇒ Object
- #body_size ⇒ Object
-
#initialize(body) ⇒ MessageBodyValidator
constructor
A new instance of MessageBodyValidator.
- #proper_length? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(body) ⇒ MessageBodyValidator
Returns a new instance of MessageBodyValidator.
16 17 18 |
# File 'lib/client_smsapi/validators/message_body_validator.rb', line 16 def initialize(body) @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
14 15 16 |
# File 'lib/client_smsapi/validators/message_body_validator.rb', line 14 def body @body end |
Class Method Details
.valid_body?(body) ⇒ Boolean
10 11 12 |
# File 'lib/client_smsapi/validators/message_body_validator.rb', line 10 def self.valid_body?(body) new(body).valid? end |
Instance Method Details
#basic_charset? ⇒ Boolean
45 46 47 |
# File 'lib/client_smsapi/validators/message_body_validator.rb', line 45 def basic_charset? @basic_charset ||= body_codepoints.all? { |c| BASIC_CHARS.codepoints.include?(c) } end |
#body_codepoints ⇒ Object
32 33 34 |
# File 'lib/client_smsapi/validators/message_body_validator.rb', line 32 def body_codepoints @body_codepoints ||= body.codepoints end |
#body_size ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/client_smsapi/validators/message_body_validator.rb', line 36 def body_size if basic_charset? double = body_codepoints.count { |codepoint| DOUBLE_COST_CHARS.codepoints.include?(codepoint) } body_codepoints.count + double else body_codepoints.count end end |
#proper_length? ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/client_smsapi/validators/message_body_validator.rb', line 24 def proper_length? if basic_charset? body_size <= BASIC_LIMIT else body_size <= EXTRA_LIMIT end end |
#valid? ⇒ Boolean
20 21 22 |
# File 'lib/client_smsapi/validators/message_body_validator.rb', line 20 def valid? proper_length? && !body.empty? end |