Class: CloudFlareLocalizable::Country
- Inherits:
-
Object
- Object
- CloudFlareLocalizable::Country
- Defined in:
- lib/cloudflare_localizable/country.rb
Overview
This class represents a country, and stores name and code for the countries.
Example
country = Country.find('BB')
country.code # => "BB"
country.name # => "Barbados"
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(code = 'XX', name = 'Unknown') ⇒ Country
constructor
A new instance of Country.
Constructor Details
#initialize(code = 'XX', name = 'Unknown') ⇒ Country
Returns a new instance of Country.
22 23 24 25 |
# File 'lib/cloudflare_localizable/country.rb', line 22 def initialize(code = 'XX', name = 'Unknown') self.code = code self.name = name end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
14 15 16 |
# File 'lib/cloudflare_localizable/country.rb', line 14 def code @code end |
#name ⇒ Object
Returns the value of attribute name.
14 15 16 |
# File 'lib/cloudflare_localizable/country.rb', line 14 def name @name end |
Class Method Details
.find(code) ⇒ Object
16 17 18 19 20 |
# File 'lib/cloudflare_localizable/country.rb', line 16 def self.find(code) record = CF_COUNTRIES.find { |country| country[:code] == code } || {} new(record.fetch(:code, 'XX'), record.fetch(:name, 'Unknown')) end |