Class: ShortPixel::Object
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- ShortPixel::Object
- Defined in:
- lib/shortpixel/object.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Object
constructor
A new instance of Object.
- #to_ostruct(obj) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Object
Returns a new instance of Object.
5 6 7 |
# File 'lib/shortpixel/object.rb', line 5 def initialize(attributes) super to_ostruct(attributes) end |
Instance Method Details
#to_ostruct(obj) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/shortpixel/object.rb', line 9 def to_ostruct(obj) if obj.is_a?(Hash) OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h) elsif obj.is_a?(Array) results = obj.map { |o| to_ostruct(o) } OpenStruct.new({ results: results }) else obj end end |