class GlobalPhone::Database

Attributes

regions[R]

Public Class Methods

load(json) click to toggle source
# File lib/global_phone/database.rb, line 12
def self.load(json)
  require 'json'
  new(JSON.parse(json))
end
load_file(filename) click to toggle source
# File lib/global_phone/database.rb, line 8
def self.load_file(filename)
  load(File.read(filename))
end
new(record_data) click to toggle source
# File lib/global_phone/database.rb, line 19
def initialize(record_data)
  @regions = record_data.map { |data| Region.new(data) }
  @territories_by_name = {}
end

Public Instance Methods

inspect() click to toggle source
# File lib/global_phone/database.rb, line 35
def inspect
  "#<#{self.class.name}>"
end
region(country_code) click to toggle source
# File lib/global_phone/database.rb, line 24
def region(country_code)
  regions_by_country_code[country_code.to_s]
end
territory(name) click to toggle source
# 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

Protected Instance Methods

region_for_territory(name) click to toggle source
# File lib/global_phone/database.rb, line 44
def region_for_territory(name)
  regions.find { |r| r.has_territory?(name) }
end
regions_by_country_code() click to toggle source
# File lib/global_phone/database.rb, line 40
def regions_by_country_code
  @regions_by_country_code ||= Hash[*regions.map { |r| [r.country_code, r] }.flatten]
end