Class: Infostrada::Match

Inherits:
BaseRequest show all
Extended by:
Forwardable
Defined in:
lib/infostrada/match.rb

Overview

You can get the information about a single game, about all games in an edition or about all games in a day.

Examples:

Infostrada::Match.where(edition_id: 2398)        # all matches for edition 2398
Infostrada::Match.where(date: Time.now)          # all matches for current date (live info)
Infostrada::Match.where(date: Date.today+1.day)  # all matches for tomorrow (live info)
Infostrada::Match.where(id: 1337)                # information about the match 1337

Constant Summary collapse

URLS =

We can get all matches for a given edition (very heavy payload). Or we can just get the match information on a single match.

{
  list: '/GetMatchList_Edition',
  single: '/GetMatchInfo',
  live_list: '/GetMatchLiveList_Date'
}

Constants inherited from BaseRequest

BaseRequest::RETRIES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseRequest

get!

Constructor Details

#initialize(hash = {}, &block) ⇒ Match

Returns a new instance of Match.



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/infostrada/match.rb', line 153

def initialize(hash = {}, &block)
  @id                        = hash['n_MatchID']
  @date                      = Formatter.format_date(hash['d_DateUTC']) if hash['d_DateUTC']
  @rescheduled               = hash['b_RescheduledToBeResumed']
  @round                     = hash['n_RoundNr']
  @time_unknown              = hash['b_TimeUnknown']
  @date_unknown              = hash['b_DateUnknown']

  @aggregate_winner_id       = hash['n_WinnerOnAggregateTeamID']
  @current_period_started_at = Formatter.format_date(hash['d_CurrentPeriodStartTime']) if hash['d_CurrentPeriodStartTime']
  @status_code               = hash['n_MatchStatusCode']
  @status                    = hash['c_MatchStatus']
  @status_short              = hash['c_MatchStatusShort']
  @leg                       = hash['n_Leg']
  @started_at                = Formatter.format_date(hash['d_MatchStartTime']) if hash['d_MatchStartTime']
  @knockout_phase_id         = hash['n_KnockoutPhaseID']

  @stadium_id                = hash['n_StadiumGeoID']
  @stadium_name              = hash['c_Stadium']
  @spectators                = hash['n_Spectators']
  @city                      = hash['c_City']

  @live                      = hash['b_Live']
  @started                   = hash['b_Started']
  @finished                  = hash['b_Finished']
  @awarded                   = hash['b_Awarded']

  @live_score                = hash['b_DataEntryLiveScore']
  @live_goals                = hash['b_DataEntryLiveGoal']
  @live_lineup               = hash['b_DataEntryLiveLineup']

  @lineup_provisional        = hash['b_LineupProvisional']
  @lineup_official           = hash['b_LineupOfficial']

  @period                    = hash['n_PeriodSort']
  @referee                   = Referee.new(hash)      if hash['n_RefereeID']
  @phase                     = Phase.new(hash)        if hash['n_PhaseID']

  @home_team                 = Team.new(hash, 'home') if hash['n_HomeTeamID']
  @away_team                 = Team.new(hash, 'away') if hash['n_AwayTeamID']

  @goals                     = Goals.new(hash)        if hash['n_HomeGoals']
  @edition                   = Edition.new(hash)      if hash['n_EditionID']

  block.call(self) if block_given?
  self
end

Instance Attribute Details

#aggregate_winner_idObject

Returns the value of attribute aggregate_winner_id.



20
21
22
# File 'lib/infostrada/match.rb', line 20

def aggregate_winner_id
  @aggregate_winner_id
end

#awardedObject

Returns the value of attribute awarded.



18
19
20
# File 'lib/infostrada/match.rb', line 18

def awarded
  @awarded
end

#away_teamObject

Returns the value of attribute away_team.



17
18
19
# File 'lib/infostrada/match.rb', line 17

def away_team
  @away_team
end

#cityObject

Returns the value of attribute city.



21
22
23
# File 'lib/infostrada/match.rb', line 21

def city
  @city
end

#current_period_started_atObject

Returns the value of attribute current_period_started_at.



20
21
22
# File 'lib/infostrada/match.rb', line 20

def current_period_started_at
  @current_period_started_at
end

#dateObject

Returns the value of attribute date.



17
18
19
# File 'lib/infostrada/match.rb', line 17

def date
  @date
end

#date_unknownObject

Returns the value of attribute date_unknown.



21
22
23
# File 'lib/infostrada/match.rb', line 21

def date_unknown
  @date_unknown
end

#editionObject

Returns the value of attribute edition.



21
22
23
# File 'lib/infostrada/match.rb', line 21

def edition
  @edition
end

#finishedObject

Returns the value of attribute finished.



18
19
20
# File 'lib/infostrada/match.rb', line 18

def finished
  @finished
end

#first_leg_scoreObject

Returns the value of attribute first_leg_score.



19
20
21
# File 'lib/infostrada/match.rb', line 19

def first_leg_score
  @first_leg_score
end

#goalsObject

Returns the value of attribute goals.



18
19
20
# File 'lib/infostrada/match.rb', line 18

def goals
  @goals
end

#home_teamObject

Returns the value of attribute home_team.



17
18
19
# File 'lib/infostrada/match.rb', line 17

def home_team
  @home_team
end

#idObject

Returns the value of attribute id.



17
18
19
# File 'lib/infostrada/match.rb', line 17

def id
  @id
end

#knockout_phase_idObject

Returns the value of attribute knockout_phase_id.



19
20
21
# File 'lib/infostrada/match.rb', line 19

def knockout_phase_id
  @knockout_phase_id
end

#legObject

Returns the value of attribute leg.



19
20
21
# File 'lib/infostrada/match.rb', line 19

def leg
  @leg
end

#lineup_officialObject

Lineup



27
28
29
# File 'lib/infostrada/match.rb', line 27

def lineup_official
  @lineup_official
end

#lineup_provisionalObject

Lineup



27
28
29
# File 'lib/infostrada/match.rb', line 27

def lineup_provisional
  @lineup_provisional
end

#liveObject

Check if the live score, live goals and live lineups are already available



24
25
26
# File 'lib/infostrada/match.rb', line 24

def live
  @live
end

#live_goalsObject

Check if the live score, live goals and live lineups are already available



24
25
26
# File 'lib/infostrada/match.rb', line 24

def live_goals
  @live_goals
end

#live_lineupObject

Check if the live score, live goals and live lineups are already available



24
25
26
# File 'lib/infostrada/match.rb', line 24

def live_lineup
  @live_lineup
end

#live_scoreObject

Check if the live score, live goals and live lineups are already available



24
25
26
# File 'lib/infostrada/match.rb', line 24

def live_score
  @live_score
end

#match_statusObject

Returns the value of attribute match_status.



18
19
20
# File 'lib/infostrada/match.rb', line 18

def match_status
  @match_status
end

#periodObject

period is taken from Infostradas n_PeriodSort, that can have one of these values:

1 = Not started 2 = 1st Half 3 = Halftime 4 = 2nd Half 5 = 90 mins 6 = 1st Extra Time 7 = 105 mins 8 = 2nd Extra Time 9 = 120 mins 10 = Penalty Shootout 11 = End



42
43
44
# File 'lib/infostrada/match.rb', line 42

def period
  @period
end

#phaseObject

Returns the value of attribute phase.



17
18
19
# File 'lib/infostrada/match.rb', line 17

def phase
  @phase
end

#postponedObject

Returns the value of attribute postponed.



19
20
21
# File 'lib/infostrada/match.rb', line 19

def postponed
  @postponed
end

#refereeObject

Returns the value of attribute referee.



19
20
21
# File 'lib/infostrada/match.rb', line 19

def referee
  @referee
end

#rescheduledObject

Returns the value of attribute rescheduled.



17
18
19
# File 'lib/infostrada/match.rb', line 17

def rescheduled
  @rescheduled
end

#roundObject

Returns the value of attribute round.



17
18
19
# File 'lib/infostrada/match.rb', line 17

def round
  @round
end

#spectatorsObject

Returns the value of attribute spectators.



19
20
21
# File 'lib/infostrada/match.rb', line 19

def spectators
  @spectators
end

#stadium_idObject

Returns the value of attribute stadium_id.



18
19
20
# File 'lib/infostrada/match.rb', line 18

def stadium_id
  @stadium_id
end

#stadium_nameObject

Returns the value of attribute stadium_name.



18
19
20
# File 'lib/infostrada/match.rb', line 18

def stadium_name
  @stadium_name
end

#startedObject

Returns the value of attribute started.



20
21
22
# File 'lib/infostrada/match.rb', line 20

def started
  @started
end

#started_atObject

Returns the value of attribute started_at.



20
21
22
# File 'lib/infostrada/match.rb', line 20

def started_at
  @started_at
end

#statusObject

Returns the value of attribute status.



20
21
22
# File 'lib/infostrada/match.rb', line 20

def status
  @status
end

#status_codeObject

status_code is taken from Infostradas n_MatchStatusCode, that can have on of these values:

2 = Line-up 4 = Not Started 8 = In Progress 16 = Interval 32 = Suspended (during the match) 128 = Finished (official result) 192 = Finished (unofficial result). This is a combination of code 64 and 128. 512 = Abandoned 1024 = Postponed 2048 = Delayed

If a match is stopped temporarily, n_MatchStatusCode is set to 32 (=Suspended). If it becomes clear that the match, after being suspended, will not be restarted on the same day, n_MatchStatusCode is set to 512 (=Abandoned).



60
61
62
# File 'lib/infostrada/match.rb', line 60

def status_code
  @status_code
end

#status_shortObject

Returns the value of attribute status_short.



17
18
19
# File 'lib/infostrada/match.rb', line 17

def status_short
  @status_short
end

#time_unknownObject

Returns the value of attribute time_unknown.



21
22
23
# File 'lib/infostrada/match.rb', line 21

def time_unknown
  @time_unknown
end

Class Method Details

.from_json(json = {}) ⇒ Object

Useful method to get a Match object from a json serialized Match object.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/infostrada/match.rb', line 104

def self.from_json(json = {})
  self.new do |match|
    match.id                        = json['id']
    match.date                      = Time.parse(json['date']) if json['date']
    match.rescheduled               = json['rescheduled']
    match.round                     = json['round']
    match.time_unknown              = json['time_unknown']
    match.date_unknown              = json['date_unknown']
    match.aggregate_winner_id       = json['aggregate_winner_id']

    if json['current_period_started_at']
      match.current_period_started_at = Time.parse(json['current_period_started_at'])
    end

    match.status_code               = json['status_code']
    match.status                    = json['status']
    match.status_short              = json['status_short']
    match.leg                       = json['leg']
    match.started_at                = Time.parse(json['started_at']) if json['started_at']
    match.knockout_phase_id         = json['knockout_phase_id']

    match.stadium_id                = json['stadium_id']
    match.stadium_name              = json['stadium_name']
    match.spectators                = json['spectators']
    match.city                      = json['city']

    match.live                      = json['live']
    match.started                   = json['started']
    match.finished                  = json['finished']
    match.awarded                   = json['awarded']

    match.live_score                = json['live_score']
    match.live_goals                = json['live_goals']
    match.live_lineup               = json['live_lineup']

    match.lineup_provisional        = json['lineup_provisional']
    match.lineup_official           = json['lineup_official']

    match.period                    = json['period']

    match.referee                   = Referee.from_json(json['referee'])        if json['referee']
    match.phase                     = Phase.from_json(json['phase'])            if json['phase']
    match.home_team                 = Team.from_json(json['home_team'], 'home') if json['home_team']
    match.away_team                 = Team.from_json(json['away_team'], 'away') if json['away_team']
    match.goals                     = Goals.from_json(json['goals'])            if json['goals']
    match.edition                   = Edition.from_json(json['edition'])        if json['edition']
  end
end

.get_match_list(options) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/infostrada/match.rb', line 89

def self.get_match_list(options)
  edition_id = options.delete(:edition_id)
  match_id = options.delete(:id)
  date = options.delete(:date)
  date = date.strftime('%Y%m%d') if date

  list = get!(URLS[:list], query: { editionid: edition_id.to_i }) if edition_id
  list = get!(URLS[:single], query: { matchid: match_id.to_i }) if match_id
  list = get!(URLS[:live_list], query: { date: date }) if date

  list
end

.where(options = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/infostrada/match.rb', line 78

def self.where(options = {})
  list = get_match_list(options)

  matches = []
  list.each do |match_hash|
    matches << Match.new(match_hash)
  end

  matches
end

Instance Method Details

#live_event_listObject



213
214
215
# File 'lib/infostrada/match.rb', line 213

def live_event_list
  event_list = MatchEventList.where(match_id: self.id)
end

#live_goals?Boolean

Returns:

  • (Boolean)


205
206
207
# File 'lib/infostrada/match.rb', line 205

def live_goals?
  @live_goals || false
end

#live_lineup?Boolean

Returns:

  • (Boolean)


209
210
211
# File 'lib/infostrada/match.rb', line 209

def live_lineup?
  @live_lineup || false
end

#live_score?Boolean

Returns:

  • (Boolean)


201
202
203
# File 'lib/infostrada/match.rb', line 201

def live_score?
  @live_score || false
end