Class: Country
- Inherits:
-
Object
- Object
- Country
- Defined in:
- lib/countries.rb
Constant Summary collapse
- Data =
Data = File.open( ‘lib/data/countries.yaml’ ) {|yaml| YAML::load( yaml )}
YAML.load_file(File.join(File.dirname(__FILE__), 'data', 'countries.yaml')) || {}
- Names =
Data.map {|code,data| data[:name]}
Instance Attribute Summary collapse
-
#alpha2 ⇒ Object
readonly
Returns the value of attribute alpha2.
-
#alpha3 ⇒ Object
readonly
Returns the value of attribute alpha3.
-
#country_code ⇒ Object
readonly
Returns the value of attribute country_code.
-
#international_prefix ⇒ Object
readonly
Returns the value of attribute international_prefix.
-
#latitude ⇒ Object
readonly
Returns the value of attribute latitude.
-
#longitude ⇒ Object
readonly
Returns the value of attribute longitude.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#national_destination_code_lengths ⇒ Object
readonly
Returns the value of attribute national_destination_code_lengths.
-
#national_number_lengths ⇒ Object
readonly
Returns the value of attribute national_number_lengths.
-
#national_prefix ⇒ Object
readonly
Returns the value of attribute national_prefix.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#subregion ⇒ Object
readonly
Returns the value of attribute subregion.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Country
constructor
A new instance of Country.
- #subdivisions ⇒ Object
- #subdivisions? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ Country
Returns a new instance of Country.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/countries.rb', line 9 def initialize(data) @number = data['number'] @alpha2 = data['alpha2'] @alpha3 = data['alpha3'] @name = data['name'] @names = data['names'] @latitude = data['latitude'] @longitude = data['longitude'] @region = data['region'] @subregion = data['subregion'] @country_code = data['e164_country_code'] @national_destination_code_lengths = data['e164_national_destination_code_lengths'] @national_number_lengths = data['e164_national_number_lengths'] @international_prefix = data['e164_international_prefix'] @national_prefix = data['e164_national_prefix'] end |
Instance Attribute Details
#alpha2 ⇒ Object (readonly)
Returns the value of attribute alpha2.
6 7 8 |
# File 'lib/countries.rb', line 6 def alpha2 @alpha2 end |
#alpha3 ⇒ Object (readonly)
Returns the value of attribute alpha3.
6 7 8 |
# File 'lib/countries.rb', line 6 def alpha3 @alpha3 end |
#country_code ⇒ Object (readonly)
Returns the value of attribute country_code.
6 7 8 |
# File 'lib/countries.rb', line 6 def country_code @country_code end |
#international_prefix ⇒ Object (readonly)
Returns the value of attribute international_prefix.
6 7 8 |
# File 'lib/countries.rb', line 6 def international_prefix @international_prefix end |
#latitude ⇒ Object (readonly)
Returns the value of attribute latitude.
6 7 8 |
# File 'lib/countries.rb', line 6 def latitude @latitude end |
#longitude ⇒ Object (readonly)
Returns the value of attribute longitude.
6 7 8 |
# File 'lib/countries.rb', line 6 def longitude @longitude end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/countries.rb', line 6 def name @name end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
6 7 8 |
# File 'lib/countries.rb', line 6 def names @names end |
#national_destination_code_lengths ⇒ Object (readonly)
Returns the value of attribute national_destination_code_lengths.
6 7 8 |
# File 'lib/countries.rb', line 6 def national_destination_code_lengths @national_destination_code_lengths end |
#national_number_lengths ⇒ Object (readonly)
Returns the value of attribute national_number_lengths.
6 7 8 |
# File 'lib/countries.rb', line 6 def national_number_lengths @national_number_lengths end |
#national_prefix ⇒ Object (readonly)
Returns the value of attribute national_prefix.
6 7 8 |
# File 'lib/countries.rb', line 6 def national_prefix @national_prefix end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
6 7 8 |
# File 'lib/countries.rb', line 6 def number @number end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
6 7 8 |
# File 'lib/countries.rb', line 6 def region @region end |
#subregion ⇒ Object (readonly)
Returns the value of attribute subregion.
6 7 8 |
# File 'lib/countries.rb', line 6 def subregion @subregion end |
Class Method Details
.[](query) ⇒ Object
31 32 33 |
# File 'lib/countries.rb', line 31 def self.[](query) self.search(query) end |
Instance Method Details
#subdivisions ⇒ Object
35 36 37 |
# File 'lib/countries.rb', line 35 def subdivisions @subdivisions ||= subdivisions? ? YAML.load_file(File.join(File.dirname(__FILE__), 'data', 'subdivisions', "#{alpha2}.yaml")) : {} end |
#subdivisions? ⇒ Boolean
39 40 41 |
# File 'lib/countries.rb', line 39 def subdivisions? File.exist?(File.join(File.dirname(__FILE__), 'data', 'subdivisions', "#{alpha2}.yaml")) end |