Class: Phony::NationalCode
- Inherits:
-
Object
- Object
- Phony::NationalCode
- Defined in:
- lib/phony/national_code.rb
Overview
NationalCodes have a special numbers splitter, a national code splitter and a local code splitter.
Instance Attribute Summary collapse
-
#local_splitter ⇒ Object
readonly
Returns the value of attribute local_splitter.
Instance Method Summary collapse
-
#initialize(national_splitter, local_splitter) ⇒ NationalCode
constructor
A new instance of NationalCode.
-
#normalize(national_number, options = {}) ⇒ Object
Split gets a number without country code and removes a relative zero.
-
#split(national_number) ⇒ Object
Split gets a number without country code and splits it into its parts.
Constructor Details
#initialize(national_splitter, local_splitter) ⇒ NationalCode
Returns a new instance of NationalCode.
11 12 13 14 |
# File 'lib/phony/national_code.rb', line 11 def initialize national_splitter, local_splitter @national_splitter = national_splitter @local_splitter = local_splitter end |
Instance Attribute Details
#local_splitter ⇒ Object (readonly)
Returns the value of attribute local_splitter.
7 8 9 |
# File 'lib/phony/national_code.rb', line 7 def local_splitter @local_splitter end |
Instance Method Details
#normalize(national_number, options = {}) ⇒ Object
Split gets a number without country code and removes a relative zero.
Note: Some cases, like Italy, don’t remove the relative zero.
29 30 31 |
# File 'lib/phony/national_code.rb', line 29 def normalize national_number, = {} national_number.gsub(/\A0+/, EMPTY_STRING) end |
#split(national_number) ⇒ Object
Split gets a number without country code and splits it into its parts.
19 20 21 22 23 |
# File 'lib/phony/national_code.rb', line 19 def split national_number zero, ndc_or_rest, rest = @national_splitter.split national_number.dup return [zero, ndc_or_rest] unless rest [zero, ndc_or_rest, *@local_splitter.split(rest)] end |