Class: Cellularity::Esn
- Inherits:
-
Object
- Object
- Cellularity::Esn
- Defined in:
- lib/cellularity/esn.rb
Instance Attribute Summary collapse
-
#esn ⇒ Object
Returns the value of attribute esn.
Instance Method Summary collapse
-
#initialize(esn = '') ⇒ Esn
constructor
A new instance of Esn.
- #is_valid_decimal? ⇒ Boolean
- #is_valid_hexadecimal_with_prefix? ⇒ Boolean
- #is_valid_hexadecimal_without_prefix? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(esn = '') ⇒ Esn
Returns a new instance of Esn.
6 7 8 |
# File 'lib/cellularity/esn.rb', line 6 def initialize(esn = '') self.esn = esn.to_s end |
Instance Attribute Details
#esn ⇒ Object
Returns the value of attribute esn.
4 5 6 |
# File 'lib/cellularity/esn.rb', line 4 def esn @esn end |
Instance Method Details
#is_valid_decimal? ⇒ Boolean
17 18 19 20 21 22 |
# File 'lib/cellularity/esn.rb', line 17 def is_valid_decimal? # Remove leading zeros so Integer doesn't think it's an octal. !!Integer(self.esn.gsub(/^0+/, '')) rescue ArgumentError, TypeError false end |
#is_valid_hexadecimal_with_prefix? ⇒ Boolean
24 25 26 |
# File 'lib/cellularity/esn.rb', line 24 def is_valid_hexadecimal_with_prefix? self.esn =~ /0x[\h]+/i end |
#is_valid_hexadecimal_without_prefix? ⇒ Boolean
28 29 30 |
# File 'lib/cellularity/esn.rb', line 28 def is_valid_hexadecimal_without_prefix? self.esn =~ /\h+/i && !self.esn.include?('0x') end |
#valid? ⇒ Boolean
10 11 12 13 14 15 |
# File 'lib/cellularity/esn.rb', line 10 def valid? return is_valid_decimal? if self.esn.length == 11 return is_valid_hexadecimal_with_prefix? if self.esn.length == 10 return is_valid_hexadecimal_without_prefix? if self.esn.length == 8 false end |