Class: Courier::Profiles::Address
- Inherits:
-
Object
- Object
- Courier::Profiles::Address
- Defined in:
- lib/trycourier/profiles/types/address.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#formatted ⇒ Object
readonly
Returns the value of attribute formatted.
-
#locality ⇒ Object
readonly
Returns the value of attribute locality.
-
#postal_code ⇒ Object
readonly
Returns the value of attribute postal_code.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#street_address ⇒ Object
readonly
Returns the value of attribute street_address.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Profiles::Address
Deserialize a JSON object to an instance of Address.
-
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
Instance Method Summary collapse
- #initialize(formatted:, street_address:, locality:, region:, postal_code:, country:, additional_properties: nil) ⇒ Profiles::Address constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of Address to a JSON object.
Constructor Details
#initialize(formatted:, street_address:, locality:, region:, postal_code:, country:, additional_properties: nil) ⇒ Profiles::Address
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/trycourier/profiles/types/address.rb', line 18 def initialize(formatted:, street_address:, locality:, region:, postal_code:, country:, additional_properties: nil) # @type [String] @formatted = formatted # @type [String] @street_address = street_address # @type [String] @locality = locality # @type [String] @region = region # @type [String] @postal_code = postal_code # @type [String] @country = country # @type [OpenStruct] Additional properties unmapped to the current class definition @additional_properties = additional_properties end |
Instance Attribute Details
#additional_properties ⇒ Object (readonly)
Returns the value of attribute additional_properties.
8 9 10 |
# File 'lib/trycourier/profiles/types/address.rb', line 8 def additional_properties @additional_properties end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
8 9 10 |
# File 'lib/trycourier/profiles/types/address.rb', line 8 def country @country end |
#formatted ⇒ Object (readonly)
Returns the value of attribute formatted.
8 9 10 |
# File 'lib/trycourier/profiles/types/address.rb', line 8 def formatted @formatted end |
#locality ⇒ Object (readonly)
Returns the value of attribute locality.
8 9 10 |
# File 'lib/trycourier/profiles/types/address.rb', line 8 def locality @locality end |
#postal_code ⇒ Object (readonly)
Returns the value of attribute postal_code.
8 9 10 |
# File 'lib/trycourier/profiles/types/address.rb', line 8 def postal_code @postal_code end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
8 9 10 |
# File 'lib/trycourier/profiles/types/address.rb', line 8 def region @region end |
#street_address ⇒ Object (readonly)
Returns the value of attribute street_address.
8 9 10 |
# File 'lib/trycourier/profiles/types/address.rb', line 8 def street_address @street_address end |
Class Method Details
.from_json(json_object:) ⇒ Profiles::Address
Deserialize a JSON object to an instance of Address
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/trycourier/profiles/types/address.rb', line 40 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) JSON.parse(json_object) formatted = struct.formatted street_address = struct.street_address locality = struct.locality region = struct.region postal_code = struct.postal_code country = struct.country new(formatted: formatted, street_address: street_address, locality: locality, region: region, postal_code: postal_code, country: country, additional_properties: struct) end |
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
71 72 73 74 75 76 77 78 |
# File 'lib/trycourier/profiles/types/address.rb', line 71 def self.validate_raw(obj:) obj.formatted.is_a?(String) != false || raise("Passed value for field obj.formatted is not the expected type, validation failed.") obj.street_address.is_a?(String) != false || raise("Passed value for field obj.street_address is not the expected type, validation failed.") obj.locality.is_a?(String) != false || raise("Passed value for field obj.locality is not the expected type, validation failed.") obj.region.is_a?(String) != false || raise("Passed value for field obj.region is not the expected type, validation failed.") obj.postal_code.is_a?(String) != false || raise("Passed value for field obj.postal_code is not the expected type, validation failed.") obj.country.is_a?(String) != false || raise("Passed value for field obj.country is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ JSON
Serialize an instance of Address to a JSON object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/trycourier/profiles/types/address.rb', line 56 def to_json(*_args) { "formatted": @formatted, "street_address": @street_address, "locality": @locality, "region": @region, "postal_code": @postal_code, "country": @country }.to_json end |