Sha256: 9a748321f1480647edf7d1194f153773fe00d197c7a439213b30ba55f230a327

Contents?: true

Size: 648 Bytes

Versions: 1

Compression:

Stored size: 648 Bytes

Contents

require 'active_support'
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

1 entries across 1 versions & 1 rubygems

Version Path
tfe-phone-0.9.9.1 lib/phone_country.rb