Class: Blackbird::Retoure::Country

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/blackbird/retoure/country.rb

Overview

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).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Country

Returns a new instance of Country.



19
20
21
22
23
# File 'lib/blackbird/retoure/country.rb', line 19

def initialize(args = {})
  @country_iso_code = args[:country_iso_code]
  @country = args[:country]
  @state = args[:state]
end

Instance Attribute Details

#countryObject (readonly)

Returns the value of attribute country.



14
15
16
# File 'lib/blackbird/retoure/country.rb', line 14

def country
  @country
end

#country_iso_codeObject (readonly)

Returns the value of attribute country_iso_code.



14
15
16
# File 'lib/blackbird/retoure/country.rb', line 14

def country_iso_code
  @country_iso_code
end

#stateObject (readonly)

Returns the value of attribute state.



14
15
16
# File 'lib/blackbird/retoure/country.rb', line 14

def state
  @state
end

Instance Method Details

#to_jsonObject

Public: Create a JSON payload of this class.

Returns a String representing the JSON payload.



28
29
30
31
32
33
34
# File 'lib/blackbird/retoure/country.rb', line 28

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