Class: KDL::Types::Country2

Inherits:
Country show all
Defined in:
lib/kdl/types/country.rb

Constant Summary

Constants inherited from Country

KDL::Types::Country::COUNTRIES2, KDL::Types::Country::COUNTRIES3

Constants inherited from Value

Value::Null

Instance Attribute Summary

Attributes inherited from Country

#alpha2, #alpha3, #name, #numeric_code

Attributes inherited from Value

#format, #type, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value

#as_type, from, #stringify_value, #to_s

Constructor Details

#initialize(value, format: nil, type: 'country-2') ⇒ Country2

Returns a new instance of Country2.



30
31
32
# File 'lib/kdl/types/country.rb', line 30

def initialize(value, format: nil, type: 'country-2')
  super
end

Class Method Details

.call(value, type = 'country-2') ⇒ Object

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
# File 'lib/kdl/types/country.rb', line 34

def self.call(value, type = 'country-2')
  return nil unless value.is_a? ::KDL::Value::String

  country = COUNTRIES2[value.value.upcase]
  raise ArgumentError, 'invalid country-3' if country.nil?

  new(country, type: type)
end