Class: PhoneCountry

Inherits:
Struct show all
Defined in:
lib/phone_country.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) area_code

Returns the value of attribute area_code



1
2
3
# File 'lib/phone_country.rb', line 1

def area_code
  @area_code
end

- (Object) char_2_code

Returns the value of attribute char_2_code



1
2
3
# File 'lib/phone_country.rb', line 1

def char_2_code
  @char_2_code
end

- (Object) country_code

Returns the value of attribute country_code



1
2
3
# File 'lib/phone_country.rb', line 1

def country_code
  @country_code
end

- (Object) name

Returns the value of attribute name



1
2
3
# File 'lib/phone_country.rb', line 1

def name
  @name
end

Class Method Details

+ (Object) find_by_country_code(code)



20
21
22
# File 'lib/phone_country.rb', line 20

def self.find_by_country_code(code)
  @@all[code]    
end

+ (Object) load



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/phone_country.rb', line 4

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

Instance Method Details

- (Object) country_code_regexp



24
25
26
# File 'lib/phone_country.rb', line 24

def country_code_regexp
  Regexp.new("^[+]#{country_code}")    
end

- (Object) to_s



16
17
18
# File 'lib/phone_country.rb', line 16

def to_s
  name
end