Class: GlobalPhone::Database
- Inherits:
-
Object
- Object
- GlobalPhone::Database
show all
- Includes:
- Parsing
- Defined in:
- lib/global_phone/database.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Parsing
#parse, #parse_international_string
Constructor Details
#initialize(record_data) ⇒ Database
Returns a new instance of Database.
19
20
21
22
|
# File 'lib/global_phone/database.rb', line 19
def initialize(record_data)
@regions = record_data.map { |data| Region.new(data) }
@territories_by_name = {}
end
|
Instance Attribute Details
#regions ⇒ Object
Returns the value of attribute regions.
17
18
19
|
# File 'lib/global_phone/database.rb', line 17
def regions
@regions
end
|
Class Method Details
.load(json) ⇒ Object
12
13
14
15
|
# File 'lib/global_phone/database.rb', line 12
def self.load(json)
require 'json'
new(JSON.parse(json))
end
|
.load_file(filename) ⇒ Object
8
9
10
|
# File 'lib/global_phone/database.rb', line 8
def self.load_file(filename)
load(File.read(filename))
end
|
Instance Method Details
#inspect ⇒ Object
35
36
37
|
# File 'lib/global_phone/database.rb', line 35
def inspect
"#<#{self.class.name}>"
end
|
#region(country_code) ⇒ Object
24
25
26
|
# File 'lib/global_phone/database.rb', line 24
def region(country_code)
regions_by_country_code[country_code.to_s]
end
|
#territory(name) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/global_phone/database.rb', line 28
def territory(name)
name = name.to_s.upcase
@territories_by_name[name] ||= if region = region_for_territory(name)
region.territory(name)
end
end
|