Class: MasonHubAPI::Object

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/mason_hub_api/object.rb

Direct Known Subclasses

Callback, Response, Return

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Object

Returns a new instance of Object.



9
10
11
# File 'lib/mason_hub_api/object.rb', line 9

def initialize(attributes)
  super to_ostruct(attributes)
end

Instance Method Details

#to_ostruct(obj) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/mason_hub_api/object.rb', line 13

def to_ostruct(obj)
  if obj.is_a?(Hash)
    OpenStruct.new(obj.map { |key, val| [key.to_s.underscore, to_ostruct(val)] }.to_h)
  elsif obj.is_a?(Array)
    obj.map { |o| to_ostruct(o) }
  else # Assumed to be a primitive value
    obj
  end
end