Sha256: 20a00f0f599626cf1dc04274dc377127a61d8e4ed701e4e882c1a3916fee15fd
Contents?: true
Size: 662 Bytes
Versions: 2
Compression:
Stored size: 662 Bytes
Contents
module Cellularity class Esn attr_accessor :esn def initialize(esn = '') self.esn = esn.to_s end 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 def is_valid_decimal? !!Integer(self.esn) rescue ArgumentError, TypeError false end def is_valid_hexadecimal_with_prefix? self.esn =~ /0x[\h]+/i end def is_valid_hexadecimal_without_prefix? self.esn =~ /\h+/i && !self.esn.include?('0x') end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cellularity-0.0.2 | lib/cellularity/esn.rb |
cellularity-0.0.1 | lib/cellularity/esn.rb |