class GlobalPhone::Region

Public Instance Methods

formats() click to toggle source
# File lib/global_phone/region.rb, line 16
def formats
  @formats ||= format_record_data.map { |data| Format.new(data) }
end
has_territory?(name) click to toggle source
# File lib/global_phone/region.rb, line 29
def has_territory?(name)
  territory_names.include?(name.to_s.upcase)
end
inspect() click to toggle source
# File lib/global_phone/region.rb, line 41
def inspect
  "#<#{self.class.name} country_code=#{country_code} territories=[#{territory_names.join(",")}]>"
end
parse_national_string(string) click to toggle source
# File lib/global_phone/region.rb, line 33
def parse_national_string(string)
  string = Number.normalize(string)
  if starts_with_country_code?(string)
    string = strip_country_code(string)
    find_first_parsed_national_string_from_territories(string)
  end
end
territories() click to toggle source
# File lib/global_phone/region.rb, line 20
def territories
  @territories ||= territory_record_data.map { |data| Territory.new(data, self) }
end
territory(name) click to toggle source
# File lib/global_phone/region.rb, line 24
def territory(name)
  name = name.to_s.upcase
  territories.detect { |region| region.name == name }
end

Protected Instance Methods

find_first_parsed_national_string_from_territories(string) click to toggle source
# File lib/global_phone/region.rb, line 58
def find_first_parsed_national_string_from_territories(string)
  Utils.map_detect(territories) { |territory| territory.parse_national_string(string) }
end
starts_with_country_code?(string) click to toggle source
# File lib/global_phone/region.rb, line 50
def starts_with_country_code?(string)
  string.index(country_code) == 0
end
strip_country_code(string) click to toggle source
# File lib/global_phone/region.rb, line 54
def strip_country_code(string)
  string[country_code.length..-1]
end
territory_names() click to toggle source
# File lib/global_phone/region.rb, line 46
def territory_names
  territory_record_data.map(&:first)
end