Sha256: e259c8aed5bd60eef0ff6426eda0b0190c7dbc06399dd7d7c6e7712ada249e9f

Contents?: true

Size: 1.2 KB

Versions: 13

Compression:

Stored size: 1.2 KB

Contents

# typed: false
# frozen_string_literal: true

module EML
  module UK
    class Payload
      module ISO
        private

        def state=(state)
          state_or_province(state, "state")
        end

        def province=(province)
          state_or_province(province, "province")
        end

        def state_or_province(state, title)
          if EML::STATES.include?(state) || state.nil?
            instance_variable_set(:"@#{title}", state)
            return
          end

          raise(
            ArgumentError,
            "Expected #{title} to be an uppercase ISO 3166-2 code " +
            %(but received "#{state}".) + "\n" \
            "Please see http://www.unece.org/cefact/locode/subdivisions.html"
          )
        end

        def country=(country)
          if EML::COUNTRIES.include?(country) || country.nil?
            @country = country
            return
          end

          raise(
            ArgumentError,
            "Expected country to be an uppercase ISO 3166-1 alpha-3 code " +
              %(but received "#{country}".) + "\nPlease see " \
              "https://unstats.un.org/unsd/tradekb/Knowledgebase/Country-Code"
          )
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
eml-3.0.0 lib/eml/uk/payload/iso.rb
eml-2.2.0 lib/eml/uk/payload/iso.rb
eml-2.1.8 lib/eml/uk/payload/iso.rb
eml-2.1.7 lib/eml/uk/payload/iso.rb
eml-2.1.6 lib/eml/uk/payload/iso.rb
eml-2.1.5 lib/eml/uk/payload/iso.rb
eml-2.1.4 lib/eml/uk/payload/iso.rb
eml-2.1.3 lib/eml/uk/payload/iso.rb
eml-2.1.2 lib/eml/uk/payload/iso.rb
eml-2.1.1 lib/eml/uk/payload/iso.rb
eml-2.1.0 lib/eml/uk/payload/iso.rb
eml-2.0.0 lib/eml/uk/payload/iso.rb
eml-1.0.0 lib/eml/uk/payload/iso.rb