Class: Qrfy::Objects::Base

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/qrfy/objects/base.rb

Overview

# Base Qrfy Object

Base class to be subclassed from for each object generated from HTTP response.

Direct Known Subclasses

Folder, Qr

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Base

Returns a new instance of Base.



13
14
15
# File 'lib/qrfy/objects/base.rb', line 13

def initialize(attributes)
  super to_ostruct(attributes)
end

Instance Method Details

#to_ostruct(obj) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/qrfy/objects/base.rb', line 17

def to_ostruct(obj)
  if obj.is_a?(Hash)
    OpenStruct.new(obj.transform_values { |val| to_ostruct(val) })
  elsif obj.is_a?(Array)
    obj.map { |o| to_ostruct(o) }
  else
    obj
  end
end