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::Custom

#oriinal_value

Attributes inherited from Value

#format, #type, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value::Custom

#to_v1, #to_v2, #version

Methods inherited from Value

#==, #as_type, from, #inspect, #method_missing, #respond_to_missing?, #stringify_value, #to_s, #to_v2, #version

Constructor Details

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

Returns a new instance of Country2.



32
33
34
# File 'lib/kdl/types/country.rb', line 32

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class KDL::Value

Class Method Details

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

Raises:

  • (ArgumentError)


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

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