Class: DhlFreightApi::Objects::Base
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- DhlFreightApi::Objects::Base
- Defined in:
- lib/dhl_freight_api/objects/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#original_response ⇒ Object
readonly
Returns the value of attribute original_response.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Base
constructor
A new instance of Base.
- #raw ⇒ Object
- #to_hash ⇒ Object
- #to_ostruct(obj) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Base
Returns a new instance of Base.
12 13 14 15 |
# File 'lib/dhl_freight_api/objects/base.rb', line 12 def initialize(attributes) @original_response = deep_freeze_object(attributes) super(to_ostruct(attributes)) end |
Instance Attribute Details
#original_response ⇒ Object (readonly)
Returns the value of attribute original_response.
10 11 12 |
# File 'lib/dhl_freight_api/objects/base.rb', line 10 def original_response @original_response end |
Instance Method Details
#raw ⇒ Object
31 32 33 |
# File 'lib/dhl_freight_api/objects/base.rb', line 31 def raw @original_response end |
#to_hash ⇒ Object
27 28 29 |
# File 'lib/dhl_freight_api/objects/base.rb', line 27 def to_hash ostruct_to_hash(self) end |
#to_ostruct(obj) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/dhl_freight_api/objects/base.rb', line 17 def to_ostruct(obj) if obj.is_a?(Hash) OpenStruct.new(obj.transform_keys { |key| key.to_s.underscore }.transform_values { |val| to_ostruct(val) }) elsif obj.is_a?(Array) obj.map { |o| to_ostruct(o) } else obj end end |