Class: I18nPhoneNumbers::NumberFormat
- Inherits:
-
Object
- Object
- I18nPhoneNumbers::NumberFormat
- Defined in:
- lib/i18n_phone_numbers/number_format.rb
Instance Attribute Summary collapse
-
#carrier_code_formatting_rule ⇒ Object
pattern is a regex that is used to match the national (significant) number.
-
#format ⇒ Object
pattern is a regex that is used to match the national (significant) number.
-
#leading_digits_patterns ⇒ Object
pattern is a regex that is used to match the national (significant) number.
-
#national_prefix_formatting_rule ⇒ Object
pattern is a regex that is used to match the national (significant) number.
-
#pattern ⇒ Object
pattern is a regex that is used to match the national (significant) number.
Instance Method Summary collapse
-
#initialize(hash, regionMetadata) ⇒ NumberFormat
constructor
A new instance of NumberFormat.
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, regionMetadata) 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"] || regionMetadata.national_prefix_formatting_rule if !self.national_prefix_formatting_rule.blank? self.national_prefix_formatting_rule = self.national_prefix_formatting_rule. sub("$NP", regionMetadata.national_prefix). sub("$FG", "\\\\1") end self.carrier_code_formatting_rule = hash["carrierCodeFormattingRule"] || '' end |
Instance Attribute Details
#carrier_code_formatting_rule ⇒ Object
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 |
#format ⇒ Object
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_patterns ⇒ Object
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_rule ⇒ Object
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 |
#pattern ⇒ Object
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 |