Sha256: b4518756453cd1b15e9c3a72f96e7db40a20abc7c13e4dc7c104f4dea54ac3cc

Contents?: true

Size: 623 Bytes

Versions: 4

Compression:

Stored size: 623 Bytes

Contents

class PhoneCountry < Struct.new(:name, :country_code, :char_2_code, :area_code)
  cattr_accessor :all
  
  def self.load
    return @@all if @@all.present?
    
    data_file = File.join(File.dirname(__FILE__), '..', 'data', 'phone_countries.yml')
    
    @@all = {}
    YAML.load(File.read(data_file)).each_pair do |key, c|
      @@all[key] = PhoneCountry.new(c[:name], c[:country_code], c[:char_2_code], c[:area_code])
    end
    @@all
  end
  
  def to_s
    name
  end
  
  def self.find_by_country_code(code)
    @@all[code]    
  end
  
  def country_code_regexp
    Regexp.new("^[+]#{country_code}")    
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
phone-0.9.9.3 lib/phone_country.rb
elskwid-phone-0.9.9.4 lib/phone_country.rb
elskwid-phone-0.9.9.3 lib/phone_country.rb
elskwid-phone-0.9.9.2 lib/phone_country.rb