Class: Sportradar::Api::Soccer::Season
- Defined in:
- lib/sportradar/api/soccer/season.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#competition ⇒ Object
readonly
Returns the value of attribute competition.
-
#current_season ⇒ Object
readonly
Returns the value of attribute current_season.
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#league_group ⇒ Object
readonly
Returns the value of attribute league_group.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#season_coverage_info ⇒ Object
readonly
Returns the value of attribute season_coverage_info.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
Instance Method Summary collapse
- #api ⇒ Object
- #current? ⇒ Boolean
- #get_schedule ⇒ Object
- #ingest_schedule(data) ⇒ Object
-
#initialize(data = {}, competition: nil, **opts) ⇒ Season
constructor
A new instance of Season.
- #matches ⇒ Object
- #parse_schedule(data) ⇒ Object
- #path_base ⇒ Object
- #path_schedule ⇒ Object
- #queue_schedule ⇒ Object
- #update(data, **opts) ⇒ Object
Methods inherited from Data
#all_attributes, #attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data
Constructor Details
#initialize(data = {}, competition: nil, **opts) ⇒ Season
Returns a new instance of Season.
7 8 9 10 11 12 13 14 15 |
# File 'lib/sportradar/api/soccer/season.rb', line 7 def initialize(data = {}, competition: nil, **opts) @response = data @id = data["id"] @api = opts[:api] @competition = competition @matches_hash = {} update(data, **opts) end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
5 6 7 |
# File 'lib/sportradar/api/soccer/season.rb', line 5 def category @category end |
#competition ⇒ Object (readonly)
Returns the value of attribute competition.
5 6 7 |
# File 'lib/sportradar/api/soccer/season.rb', line 5 def competition @competition end |
#current_season ⇒ Object (readonly)
Returns the value of attribute current_season.
5 6 7 |
# File 'lib/sportradar/api/soccer/season.rb', line 5 def current_season @current_season end |
#end_date ⇒ Object (readonly)
Returns the value of attribute end_date.
5 6 7 |
# File 'lib/sportradar/api/soccer/season.rb', line 5 def end_date @end_date end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/soccer/season.rb', line 5 def id @id end |
#league_group ⇒ Object (readonly)
Returns the value of attribute league_group.
5 6 7 |
# File 'lib/sportradar/api/soccer/season.rb', line 5 def league_group @league_group end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/sportradar/api/soccer/season.rb', line 5 def name @name end |
#season_coverage_info ⇒ Object (readonly)
Returns the value of attribute season_coverage_info.
5 6 7 |
# File 'lib/sportradar/api/soccer/season.rb', line 5 def season_coverage_info @season_coverage_info end |
#start_date ⇒ Object (readonly)
Returns the value of attribute start_date.
5 6 7 |
# File 'lib/sportradar/api/soccer/season.rb', line 5 def start_date @start_date end |
Instance Method Details
#api ⇒ Object
60 61 62 |
# File 'lib/sportradar/api/soccer/season.rb', line 60 def api @api ||= Sportradar::Api::Soccer::Api.new(league_group: @league_group) end |
#current? ⇒ Boolean
def get_tournament_id(data, **opts)
@tournament_id ||= if opts[:tournament]
opts[:tournament].id
elsif data['tournament_id']
data['tournament_id']
elsif data['tournament']
data.dig('tournament', 'id')
end
end
46 47 48 |
# File 'lib/sportradar/api/soccer/season.rb', line 46 def current? !!@current end |
#get_schedule ⇒ Object
71 72 73 74 |
# File 'lib/sportradar/api/soccer/season.rb', line 71 def get_schedule data = api.get_data(path_schedule).to_h ingest_schedule(data) end |
#ingest_schedule(data) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/sportradar/api/soccer/season.rb', line 75 def ingest_schedule(data) @schedule_retrieved = true update(data) # TODO parse the rest of the data. keys: ["tournament", "sport_events"] data end |
#matches ⇒ Object
50 51 52 |
# File 'lib/sportradar/api/soccer/season.rb', line 50 def matches @matches_hash.values end |
#parse_schedule(data) ⇒ Object
54 55 56 57 58 |
# File 'lib/sportradar/api/soccer/season.rb', line 54 def parse_schedule(data) if data['schedules'] create_data(@matches_hash, data['schedules'], klass: Match, api: api, competition: @competition, season: self) end end |
#path_base ⇒ Object
64 65 66 |
# File 'lib/sportradar/api/soccer/season.rb', line 64 def path_base "seasons/#{@id}" end |
#path_schedule ⇒ Object
68 69 70 |
# File 'lib/sportradar/api/soccer/season.rb', line 68 def path_schedule "#{ path_base }/schedules" end |
#queue_schedule ⇒ Object
81 82 83 84 |
# File 'lib/sportradar/api/soccer/season.rb', line 81 def queue_schedule url, headers, , timeout = api.get_request_info(path_schedule) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_schedule)} end |
#update(data, **opts) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sportradar/api/soccer/season.rb', line 17 def update(data, **opts) @league_group = opts[:league_group] || data['league_group'] || @league_group @id = data['id'] || data['season_id'] || @id @current = opts[:current] || @current # get_tournament_id(data, **opts) @name = data['name'] || @name @start_date = data['start_date'] || @start_date @end_date = data['end_date'] || @end_date @year = data['year'] || @year @scheduled = data['scheduled'] || @scheduled @played = data['played'] || @played @max_coverage_level = data['max_coverage_level'] || @max_coverage_level @max_covered = data['max_covered'] || @max_covered @min_coverage_level = data['min_coverage_level'] || @min_coverage_level parse_schedule(data) end |