Class: Openf1::Object
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Openf1::Object
- Defined in:
- lib/openf1/object.rb
Direct Known Subclasses
CarData, Drivers, Intervals, Laps, Location, Meetings, Pit, Position, RaceControl, Sessions, Stints, TeamRadio, Weather
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.
7 8 9 10 11 12 |
# File 'lib/openf1/object.rb', line 7 def initialize(attributes) raise ArgumentError, "Response cannot be nil" if attributes.nil? # Response is always an array so nest under data: super(data: to_ostruct(attributes)) end |
Instance Method Details
#to_ostruct(obj) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/openf1/object.rb', line 14 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 |