Class: Mintsoft::Base
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Mintsoft::Base
- Defined in:
- lib/mintsoft/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
Get the raw original response data.
-
#to_hash ⇒ Object
Convert back to hash representation.
- #to_ostruct(obj) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Base
Returns a new instance of Base.
11 12 13 14 |
# File 'lib/mintsoft/base.rb', line 11 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.
9 10 11 |
# File 'lib/mintsoft/base.rb', line 9 def original_response @original_response end |
Instance Method Details
#raw ⇒ Object
Get the raw original response data
32 33 34 |
# File 'lib/mintsoft/base.rb', line 32 def raw @original_response end |
#to_hash ⇒ Object
Convert back to hash representation
27 28 29 |
# File 'lib/mintsoft/base.rb', line 27 def to_hash ostruct_to_hash(self) end |
#to_ostruct(obj) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/mintsoft/base.rb', line 16 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 # Assumed to be a primitive value obj end end |