Class: Booker::Models::Country

Inherits:
Type show all
Defined in:
lib/booker/models/country.rb

Constant Summary collapse

IDS_TO_ISO_CODES =

ISO 3166-1 alpha-2 Codes

YAML::load_file(File.join(__dir__, '..', 'config', 'booker_country_ids_to_iso_codes.yml')).freeze

Instance Attribute Summary

Attributes inherited from Type

#ID, #Name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

constantize, from_hash, from_list, #initialize, time_from_booker_datetime, time_to_booker_datetime, timezone_from_booker_offset!, timezone_from_booker_timezone, #to_hash, #to_json, to_wday

Constructor Details

This class inherits a constructor from Booker::Models::Model

Class Method Details

.from_country_code(code) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/booker/models/country.rb', line 9

def self.from_country_code(code)
  country = self.new ID: IDS_TO_ISO_CODES.detect{|k, v| v == code}.try(:[], 0)
  if country.ID.nil?
    raise ArgumentError, 'Country code not recognized'
  else
    country
  end
end

Instance Method Details

#country_codeObject



7
# File 'lib/booker/models/country.rb', line 7

def country_code; IDS_TO_ISO_CODES[self.ID]; end