class Phony::TrunkCode

Public Class Methods

new(code, options = {}) click to toggle source

Parameters:

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

Options:

* normalize: [true (default), false] Remove the trunk code when normalizing (only use if number scheme is defined unambiguously).
* split: [true, false (default)] Remove the trunk code when splitting (only use if number scheme is defined unambiguously).
* format: [true (default), false] Add the trunk code when formatting (passing `false` will not add it).
# File lib/phony/trunk_code.rb, line 13
def initialize(code, options = {})
  @code = code
  @trunk_code_replacement = /\A#{code.gsub(/%s/, '')}/
  @normalize = options[:normalize] || options[:normalize].nil?
  @split     = options[:split]
  @format    = options[:format] || options[:format].nil?
end

Public Instance Methods

format(space, force = nil) click to toggle source

Format the trunk code using the spaces given.

# File lib/phony/trunk_code.rb, line 45
def format(space, force = nil)
  return unless force || @format
    if @code.size > 1
      (@code % space).gsub(/\D/, ' ')
    else
      @code
    end
  
end
normalize(national_number, options = {}) click to toggle source

Normalize normalizes the given national number.

# File lib/phony/trunk_code.rb, line 38
def normalize(national_number, options = {})
  national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @normalize && options[:cc]
  national_number
end
split(national_number) click to toggle source

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

# File lib/phony/trunk_code.rb, line 31
def split(national_number)
  national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @split
  [self, national_number]
end
|(other) click to toggle source

Prepends itself to the other codes.

# File lib/phony/trunk_code.rb, line 23
def |(other)
  other.codes.unshift self
  other
end