Class: I18nPhoneNumbers::NumberFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_phone_numbers/number_format.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, regionMetadata) ⇒ NumberFormat

Returns a new instance of NumberFormat.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/i18n_phone_numbers/number_format.rb', line 59

def initialize(hash, )
  
  self.pattern = hash["pattern"] || ''
  self.format = (hash["format"] || '').gsub("$", '\\') # regexp substitution in ruby uses '\1' references instead of '$1'
  
  if !hash["leadingDigits"].blank?
    leadingDigits = hash["leadingDigits"].class != Array ? [hash["leadingDigits"]] : hash["leadingDigits"]
    self.leading_digits_patterns = leadingDigits.collect { |ld| ld.gsub(/\r?\n */,'') }
  else
    self.leading_digits_patterns = []
  end
  
  # national_prefix_formatting_rule
  self.national_prefix_formatting_rule = hash["nationalPrefixFormattingRule"] ||
                                         .national_prefix_formatting_rule
  
  if !self.national_prefix_formatting_rule.blank?
    self.national_prefix_formatting_rule = self.national_prefix_formatting_rule.
                                                sub("$NP", .national_prefix).
                                                sub("$FG", "\\\\1")
  end
  
  self.carrier_code_formatting_rule = hash["carrierCodeFormattingRule"] || ''
  
end

Instance Attribute Details

#carrier_code_formatting_ruleObject

pattern is a regex that is used to match the national (significant) number. For example, the pattern “(20)(d4)(d4)” will match number “2070313000”, which is the national (significant) number for Google London. Note the presence of the parentheses, which are capturing groups what specifies the grouping of numbers.



10
11
12
# File 'lib/i18n_phone_numbers/number_format.rb', line 10

def carrier_code_formatting_rule
  @carrier_code_formatting_rule
end

#formatObject

pattern is a regex that is used to match the national (significant) number. For example, the pattern “(20)(d4)(d4)” will match number “2070313000”, which is the national (significant) number for Google London. Note the presence of the parentheses, which are capturing groups what specifies the grouping of numbers.



10
11
12
# File 'lib/i18n_phone_numbers/number_format.rb', line 10

def format
  @format
end

#leading_digits_patternsObject

pattern is a regex that is used to match the national (significant) number. For example, the pattern “(20)(d4)(d4)” will match number “2070313000”, which is the national (significant) number for Google London. Note the presence of the parentheses, which are capturing groups what specifies the grouping of numbers.



10
11
12
# File 'lib/i18n_phone_numbers/number_format.rb', line 10

def leading_digits_patterns
  @leading_digits_patterns
end

#national_prefix_formatting_ruleObject

pattern is a regex that is used to match the national (significant) number. For example, the pattern “(20)(d4)(d4)” will match number “2070313000”, which is the national (significant) number for Google London. Note the presence of the parentheses, which are capturing groups what specifies the grouping of numbers.



10
11
12
# File 'lib/i18n_phone_numbers/number_format.rb', line 10

def national_prefix_formatting_rule
  @national_prefix_formatting_rule
end

#patternObject

pattern is a regex that is used to match the national (significant) number. For example, the pattern “(20)(d4)(d4)” will match number “2070313000”, which is the national (significant) number for Google London. Note the presence of the parentheses, which are capturing groups what specifies the grouping of numbers.



10
11
12
# File 'lib/i18n_phone_numbers/number_format.rb', line 10

def pattern
  @pattern
end