Sha256: 42643e174d22c5885e1c5332a3ed74a04b5d8e24dd95e0030f8ce1685d7c290c

Contents?: true

Size: 659 Bytes

Versions: 3

Compression:

Stored size: 659 Bytes

Contents

module Phoner
  class Country < 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] = Country.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
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
phone-1.2.2 lib/country.rb
phone-1.2.1 lib/country.rb
phone-1.0 lib/country.rb