Class: GlobalPhone::Region

Inherits:
Record
  • Object
show all
Defined in:
lib/global_phone/region.rb

Instance Method Summary collapse

Methods inherited from Record

field, #initialize

Constructor Details

This class inherits a constructor from GlobalPhone::Record

Instance Method Details

#formatsObject



16
17
18
# File 'lib/global_phone/region.rb', line 16

def formats
  @formats ||= format_record_data.map { |data| Format.new(data) }
end

#has_territory?(name) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/global_phone/region.rb', line 29

def has_territory?(name)
  territory_names.include?(name.to_s.upcase)
end

#inspectObject



41
42
43
# 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) ⇒ Object



33
34
35
36
37
38
39
# 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

#territoriesObject



20
21
22
# File 'lib/global_phone/region.rb', line 20

def territories
  @territories ||= territory_record_data.map { |data| Territory.new(data, self) }
end

#territory(name) ⇒ Object



24
25
26
27
# File 'lib/global_phone/region.rb', line 24

def territory(name)
  name = name.to_s.upcase
  territories.detect { |region| region.name == name }
end