Class: Blackbird::Retoure::Country
- Inherits:
-
Object
- Object
- Blackbird::Retoure::Country
- 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
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#country_iso_code ⇒ Object
readonly
Returns the value of attribute country_iso_code.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Country
constructor
A new instance of Country.
-
#to_json ⇒ Object
Public: Create a JSON payload of this class.
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
#country ⇒ Object (readonly)
Returns the value of attribute country.
14 15 16 |
# File 'lib/blackbird/retoure/country.rb', line 14 def country @country end |
#country_iso_code ⇒ Object (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 |
#state ⇒ Object (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_json ⇒ Object
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 |