Class: Msisdn
- Inherits:
-
Object
- Object
- Msisdn
- Defined in:
- lib/msisdn.rb
Constant Summary collapse
- INTERNATIONAL_COUNTRY_CODE =
/^\+(1|2[1-689]\d|2[07]|3[0-469]|3[578]\d|4[0-13-9]|42\d|5[09]\d|5[1-8]|6[0-6]|6[7-9]\d|7|8[035789]\d|8[1246]|9[0-58]|9[679]\d)(\d+)/
- INTERNATIONAL_COUNTRY_CODE_NO_PREFIX =
/(1|2[1-689]\d|2[07]|3[0-469]|3[578]\d|4[0-13-9]|42\d|5[09]\d|5[1-8]|6[0-6]|6[7-9]\d|7|8[035789]\d|8[1246]|9[0-58]|9[679]\d)(\d+)/
- EXACTLY_10_DIGITS =
/^(\d{10})$/
- SPECIAL_CASES =
Some countries with trunk code requirement for local dialling See en.wikipedia.org/wiki/Telephone_numbering_plan TODO: Special case until I need another country which don’t use trunk code and/or 10 digit number plan
{ "995" => [9, '0'] }
Instance Attribute Summary collapse
-
#country_code ⇒ Object
Returns the value of attribute country_code.
-
#dialing_code ⇒ Object
Returns the value of attribute dialing_code.
-
#msisdn ⇒ Object
Returns the value of attribute msisdn.
-
#national_number ⇒ Object
Returns the value of attribute national_number.
-
#network ⇒ Object
Returns the value of attribute network.
-
#original ⇒ Object
Returns the value of attribute original.
Instance Method Summary collapse
-
#initialize(msisdn, default_country_code = nil) ⇒ Msisdn
constructor
A new instance of Msisdn.
- #international ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(msisdn, default_country_code = nil) ⇒ Msisdn
Returns a new instance of Msisdn.
23 24 25 26 27 28 29 30 31 |
# File 'lib/msisdn.rb', line 23 def initialize(msisdn, default_country_code = nil) msisdn.gsub!( /[\s()\-a-zA-Z]/, '') @default_country_code = default_country_code @original = @msisdn = msisdn unless match_local(msisdn) match_international end end |
Instance Attribute Details
#country_code ⇒ Object
Returns the value of attribute country_code.
9 10 11 |
# File 'lib/msisdn.rb', line 9 def country_code @country_code end |
#dialing_code ⇒ Object
Returns the value of attribute dialing_code.
9 10 11 |
# File 'lib/msisdn.rb', line 9 def dialing_code @dialing_code end |
#msisdn ⇒ Object
Returns the value of attribute msisdn.
9 10 11 |
# File 'lib/msisdn.rb', line 9 def msisdn @msisdn end |
#national_number ⇒ Object
Returns the value of attribute national_number.
9 10 11 |
# File 'lib/msisdn.rb', line 9 def national_number @national_number end |
#network ⇒ Object
Returns the value of attribute network.
9 10 11 |
# File 'lib/msisdn.rb', line 9 def network @network end |
#original ⇒ Object
Returns the value of attribute original.
9 10 11 |
# File 'lib/msisdn.rb', line 9 def original @original end |
Instance Method Details
#international ⇒ Object
33 34 35 36 |
# File 'lib/msisdn.rb', line 33 def international return nil if @country_code.nil? "#{@country_code}#{@network}#{@subscriber}" end |
#valid? ⇒ Boolean
38 39 40 41 |
# File 'lib/msisdn.rb', line 38 def valid? return true if @network and @subscriber.length >= 7 false end |