Class: PrizePicks::Base
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- PrizePicks::Base
show all
- Defined in:
- lib/prizepicks/objects/base.rb
Instance Method Summary
collapse
Constructor Details
#initialize(resp) ⇒ Base
Returns a new instance of Base.
6
7
8
9
|
# File 'lib/prizepicks/objects/base.rb', line 6
def initialize(resp)
@resp = resp
super to_obstruct(attributes)
end
|
Instance Method Details
#attributes ⇒ Object
11
12
13
|
# File 'lib/prizepicks/objects/base.rb', line 11
def attributes
@resp.dig('data', 'attributes') || @resp['attributes']
end
|
#data ⇒ Object
15
16
17
|
# File 'lib/prizepicks/objects/base.rb', line 15
def data
@resp['data'] || @resp
end
|
#to_obstruct(obj) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/prizepicks/objects/base.rb', line 19
def to_obstruct(obj)
case obj
when Hash
OpenStruct.new(obj.transform_values { |val| to_obstruct(val) })
when Array
obj.map { |o| to_obstruct(o) }
else
obj
end
end
|