Class: Phony::TrunkCode

Inherits:
Object
  • Object
show all
Defined in:
lib/phony/trunk_code.rb

Instance Method Summary collapse

Constructor Details

#initialize(code, options = {}) ⇒ TrunkCode

Parameters:

* code: The trunk code, e.g. 0.

Options:

* normalize: Remove the trunk code when normalizing (only use if number scheme is defined unambiguously).
* split: Remove the trunk code when splitting (only use if number scheme is defined unambiguously).

12
13
14
15
16
17
# File 'lib/phony/trunk_code.rb', line 12

def initialize code, options = {}
  @code = code
  @trunk_code_replacement = /\A#{code.gsub(%r{%s}, '')}/
  @normalize = options[:normalize] || options[:normalize].nil?
  @split     = options[:split]
end

Instance Method Details

#normalize(national_number) ⇒ Object


34
35
36
37
# File 'lib/phony/trunk_code.rb', line 34

def normalize national_number
  national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @normalize
  return national_number
end

#split(national_number) ⇒ Object

Split gets a number without country code and splits it into its parts.


29
30
31
32
# File 'lib/phony/trunk_code.rb', line 29

def split national_number
  national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @split
  return [@code, national_number]
end

#|(other) ⇒ Object

Prepends itself to the other codes.


21
22
23
24
# File 'lib/phony/trunk_code.rb', line 21

def | other
  other.codes.unshift self
  other
end