Class: Country
- Inherits:
-
Object
- Object
- Country
- Defined in:
- lib/country_list/country.rb
Constant Summary collapse
- ATTR_READERS =
[ :alpha2, :name, :eu_member, :currency_code ]
- @@country_codes =
nil- @@cached_countries =
nil
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
- .[](country_code) ⇒ Object
-
.all ⇒ Object
Returns big array with all countries.
- .country_codes ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #eu_member? ⇒ Boolean
- #in_europe? ⇒ Boolean
-
#initialize(country_code) ⇒ Country
constructor
A new instance of Country.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(country_code) ⇒ Country
Returns a new instance of Country.
22 23 24 |
# File 'lib/country_list/country.rb', line 22 def initialize(country_code) @data = CountryList::Data.new(country_code).call end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/country_list/country.rb', line 7 def data @data end |
Class Method Details
.[](country_code) ⇒ Object
57 58 59 60 |
# File 'lib/country_list/country.rb', line 57 def [](country_code) country = new(country_code) (country && country.valid?) ? country : nil end |
.all ⇒ Object
Returns big array with all countries
53 54 55 |
# File 'lib/country_list/country.rb', line 53 def all CountryList::Data.countries.map{ |country_code, data| Country.new(country_code) } end |
.country_codes ⇒ Object
62 63 64 |
# File 'lib/country_list/country.rb', line 62 def country_codes CountryList::Data.country_codes end |
Instance Method Details
#<=>(other) ⇒ Object
26 27 28 |
# File 'lib/country_list/country.rb', line 26 def <=>(other) to_s <=> other.to_s end |
#==(other) ⇒ Object
30 31 32 |
# File 'lib/country_list/country.rb', line 30 def ==(other) @data == other.data end |
#eu_member? ⇒ Boolean
42 43 44 |
# File 'lib/country_list/country.rb', line 42 def eu_member? @data && @data['eu_member'].nil? ? false : @data['eu_member'] end |
#in_europe? ⇒ Boolean
46 47 48 |
# File 'lib/country_list/country.rb', line 46 def in_europe? @data && @data['continent'].nil? ? false : @data['continent'] == 'Europe' end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/country_list/country.rb', line 38 def to_s name end |
#valid? ⇒ Boolean
34 35 36 |
# File 'lib/country_list/country.rb', line 34 def valid? !(@data.nil? || @data.empty?) end |