Sha256: e27dc58748105ccf300384cdabe0bf7283de76c8c63aeb4144fcbbc27869d0f0
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 KB
Contents
require 'active_model' module Blackbird module Retoure # Public: This class represents the Country section of the DHL payload. # It validates the fields and provides a #to_json function. # # country_iso_code - String alpha-3 ISO country code. # country - String country designation (optional). # state - String state (optional). class Country include ::ActiveModel::Validations attr_reader :country_iso_code, :country, :state validates :country_iso_code, presence: true, length: { is: 3 } validates :country, :state, length: { in: 0..30 }, allow_nil: true def initialize(args = {}) @country_iso_code = args[:country_iso_code] @country = args[:country] @state = args[:state] end # Public: Create a JSON payload of this class. # # Returns a String representing the JSON payload. def to_json json = { countryISOCode: @country_iso_code } json.store(:country, @country) unless @country.blank? json.store(:state, @state) unless @state.blank? json.to_json end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
blackbird-retoure-0.1.0 | lib/blackbird/retoure/country.rb |