Class: Booker::V4::Models::Country

Inherits:
Type
  • Object
show all
Defined in:
lib/booker/v4/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

Constants inherited from Model

Model::CONSTANTIZE_MODULE

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, #to_hash, #to_json

Constructor Details

This class inherits a constructor from Booker::Model

Class Method Details

.from_country_code(code) ⇒ Object



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

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



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

def country_code; IDS_TO_ISO_CODES[self.ID]; end