Class: Dcc::Type::IsoCountryCode

Inherits:
Lutaml::Model::Type::String
  • Object
show all
Defined in:
lib/dcc/type/iso_country_code.rb

Overview

ISO 3166-1 alpha-2 country code (two uppercase letters, e.g. "DE"). Used by dcc:countryCodeISO3166_1.

Constant Summary collapse

PATTERN =
/\A[A-Z]{2}\z/.freeze

Class Method Summary collapse

Class Method Details

.cast(value) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/dcc/type/iso_country_code.rb', line 12

def self.cast(value)
  return nil unless value.is_a?(::String) && value != ""

  unless PATTERN.match?(value)
    raise Lutaml::Model::Type::InvalidValueError.new(value, "invalid ISO 3166-1 alpha-2 country code: #{value.inspect}")
  end

  value
end