class Phony::TrunkCode
Public Class Methods
new(code, options = {})
click to toggle source
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).
# 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] @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 44 def format space, force = nil if force || @format if @code.size > 1 (@code % space).gsub(/\D/, ' ') else @code end end end
normalize(national_number)
click to toggle source
Normalize normalizes the given national number.
# File lib/phony/trunk_code.rb, line 37 def normalize national_number national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @normalize return 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 30 def split national_number national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @split return [self, national_number] end
|(other)
click to toggle source
Prepends itself to the other codes.
# File lib/phony/trunk_code.rb, line 22 def | other other.codes.unshift self other end