Class: ApiSports::Object
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- ApiSports::Object
- Defined in:
- lib/api_sports/object.rb
Overview
Class to make access to response data easier e.g. response.name instead of response Inspired by github.com/tolbkni/vultr.rb and gorails.com/episodes/api-requests-with-faraday
Direct Known Subclasses
Bet, Bookmaker, Country, Event, Fixture, FixtureRound, League, Lineup, Odds, Player, Prediction, Season, Standing, Statistics, Team, Timezone, Venue
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.
12 13 14 |
# File 'lib/api_sports/object.rb', line 12 def initialize(attributes) super to_ostruct(attributes) end |
Instance Method Details
#to_ostruct(obj) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/api_sports/object.rb', line 16 def to_ostruct(obj) if obj.is_a?(Hash) OpenStruct.new(obj.transform_values { | value | to_ostruct(value) }) elsif obj.is_a?(Array) obj.map { |o| to_ostruct(o) } else obj # Assumed to be primitive type end end |