Class: CloudFlareLocalizable::Country

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#codeObject

Returns the value of attribute code.



14
15
16
# File 'lib/cloudflare_localizable/country.rb', line 14

def code
  @code
end

#nameObject

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