Class: Match

Inherits:
Object show all
Defined in:
lib/fifadat/models/match.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, team1:, team2:, score: nil, stage: nil, group: nil, matchday: nil, num: nil, datetime_utc: nil, date_local: nil, time_local: nil, timed: nil, stadium: nil, home: nil, attendance: nil) ⇒ Match

Returns a new instance of Match.



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
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/fifadat/models/match.rb', line 127

def initialize(
      status:,
      team1:,
      team2:,
      score: nil,

      stage: nil,
      group: nil,
      matchday: nil,
      num: nil,

      datetime_utc: nil,
      date_local: nil,
      time_local: nil,
      timed: nil,

      stadium: nil,
      home: nil,
      attendance: nil)
  @status = status
  @team1 = team1
  @team2 = team2
  @score = score

  @stage    = stage
  @group    = group
  @matchday = matchday
  @num      = num

  @datetime_utc = datetime_utc
  @date_local = date_local
  @time_local = time_local
  @timed = timed

  @stadium = stadium
  @home = home
  @attendance = attendance
end

Instance Attribute Details

#attendance ⇒ Object (readonly)

Returns the value of attribute attendance.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def attendance
  @attendance
end

#date_local ⇒ Object (readonly)

Returns the value of attribute date_local.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def date_local
  @date_local
end

#datetime_utc ⇒ Object (readonly)

Returns the value of attribute datetime_utc.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def datetime_utc
  @datetime_utc
end

#goals1 ⇒ Object

Returns the value of attribute goals1.



120
121
122
# File 'lib/fifadat/models/match.rb', line 120

def goals1
  @goals1
end

#goals2 ⇒ Object

Returns the value of attribute goals2.



120
121
122
# File 'lib/fifadat/models/match.rb', line 120

def goals2
  @goals2
end

#group ⇒ Object (readonly)

Returns the value of attribute group.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def group
  @group
end

#home ⇒ Object (readonly)

Returns the value of attribute home.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def home
  @home
end

#matchday ⇒ Object (readonly)

Returns the value of attribute matchday.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def matchday
  @matchday
end

#num ⇒ Object (readonly)

Returns the value of attribute num.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def num
  @num
end

#officials ⇒ Object

Returns the value of attribute officials.



120
121
122
# File 'lib/fifadat/models/match.rb', line 120

def officials
  @officials
end

#penalties ⇒ Object

Returns the value of attribute penalties.



120
121
122
# File 'lib/fifadat/models/match.rb', line 120

def penalties
  @penalties
end

#score ⇒ Object

Returns the value of attribute score.



120
121
122
# File 'lib/fifadat/models/match.rb', line 120

def score
  @score
end

#sentoff1 ⇒ Object

Returns the value of attribute sentoff1.



120
121
122
# File 'lib/fifadat/models/match.rb', line 120

def sentoff1
  @sentoff1
end

#sentoff2 ⇒ Object

Returns the value of attribute sentoff2.



120
121
122
# File 'lib/fifadat/models/match.rb', line 120

def sentoff2
  @sentoff2
end

#stadium ⇒ Object (readonly)

Returns the value of attribute stadium.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def stadium
  @stadium
end

#stage ⇒ Object (readonly)

Returns the value of attribute stage.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def stage
  @stage
end

#status ⇒ Object (readonly)

Returns the value of attribute status.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def status
  @status
end

#team1 ⇒ Object (readonly)

Returns the value of attribute team1.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def team1
  @team1
end

#team2 ⇒ Object (readonly)

Returns the value of attribute team2.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def team2
  @team2
end

#time_local ⇒ Object (readonly)

Returns the value of attribute time_local.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def time_local
  @time_local
end

#timed ⇒ Object (readonly)

Returns the value of attribute timed.



112
113
114
# File 'lib/fifadat/models/match.rb', line 112

def timed
  @timed
end

Class Method Details

.build(m, teams:, stadiums:, stages:) ⇒ Object

use _fill/build_match_basics() or such ???



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/fifadat/models/match.rb', line 6

def self.build( m, teams:, stadiums:, stages: )   ## use _fill/build_match_basics() or such ???

    rec = {}

       ## 0 =>   FINISHED/complete (OK)

       ## 1 =>   SCHEDULED/not yet played

       status = m['MatchStatus']
       timed  = m['TimeDefined']
       rec[:timed] = timed    ### note - keep timed flag too - why? why not?



       if status == 1 && timed    ## note: use TIMED (instead of SCHEDULED)

          rec[:status] = 'TIMED'
       else
          rec[:status] = MATCH_STATUS[ status ] || "#{status}-???"
       end



       rec[:stage]  = stages.find!( desc( m['StageName'] ))


       ## check optional  group, matchday, (match) num

       ##    note - matchday is a string!! (check if always a number)

       ##      ## convert to int if str - why? why not??

       group = desc( m['GroupName'] )
       rec[:group]  = group   if group

       matchday  = m['MatchDay']
       rec[:matchday]  = matchday.to_i(10)  if matchday

       num  = m['MatchNumber']
       rec[:num]  = num   if num


## e.g. if timed == false  (in at)

##     "Date":      "2027-02-27T00:00:00Z",

##     "LocalDate": "2027-02-27T01:00:00Z",


       dateTime       = parse_date_utc( m['Date'] )
       localDateTime  = parse_date_utc( m['LocalDate'] )

       if timed
         ##  pass along as is for now - why? why not

         ##   note - Date is date_utc and

         ##      LocalDate is date_local (also in utc BUT different HH:MM or possible day)

         ## note - also in utc, that is, timezone is Z (not +03:00 or such!!!)


         ## note - use datetime  - why? why not?

         ##

         ## note - cut-off/remove seconds

         rec[:datetime_utc]   = dateTime.strftime( '%Y-%m-%dT%H:%MZ' )

         ## note - use  20:30 UTC+1  or 20:30 UTC-3  for timezone format for now

         rec[:date_local] = localDateTime.strftime( '%Y-%m-%d' )
         rec[:time_local] = _fmt_time_local( dateTime, localDateTime )
       else
         ## note - uses

         ## todo/fix - assert  that utc  hour/minute is 00:00 e.g.

         ##   "2027-02-27T00:00:00Z"

         rec[:date_local] = dateTime.strftime( '%Y-%m-%d' )
       end



       if m['HomeTeam'] && m['AwayTeam']   ## assume match reports (json-style)

         team1 = teams.find!( m['HomeTeam'] )
         team2 = teams.find!( m['AwayTeam'] )
       else
         team1 =  teams.find!( m['Home'] )
         team2 =  teams.find!( m['Away'] )
       end

       rec[:team1] = team1
       rec[:team2] = team2

  #####

  #  handle score

  ## m = (full) match hash incl.  IdMatch, etc.

  ##  returns string e.g.  4-4  or 4-3 a.e.t etc


   ##

   ## fix-fix-fix

   ##   use a score class!!!

   ##   see openliga etc.


     score = _parse_score( m )


      rec[:score] = score

       ## check - never in use?

       rec[:home]  = true    if m['IsHome']


       ## add country to stadium too - why? why not?

       rec[:stadium] = stadiums.find!( m['Stadium'] )


       attendance = m['Attendance']
       rec[:attendance] = attendance.to_i(10)   if attendance


      new( **rec )
end

Instance Method Details

#as_json ⇒ Object



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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/fifadat/models/match.rb', line 168

def as_json(*)
      h = {
            'status'    => status,
            'stage'     => stage.name,
          }

       h['matchday']  = matchday     if matchday
       h['num']       = num          if num
       h['group']     = group        if group

       if timed
          h['datetime_utc'] = datetime_utc
          h['date_local'] = date_local
          h['time_local'] = time_local
       else
          h['date_local'] = date_local
       end

       h['team1']  = team1.name
       h['team2']  = team2.name

       h['score'] = score     if score && !score.empty?


       if stadium
         h['stadium'] = { 'name' => stadium.name,
                          'city' => stadium.city }
       end

       h['attendance']  if attendance



       if goals1 || goals2
         h['goals1']  = (goals1 || []).as_json
         h['goals2']  = (goals2 || []).as_json
       end

       h['penalities'] = penalties.as_json    if penalties

       if sentoff1 || sentoff2
         h['sentoff1']  = (sentoff1 || []).as_json
         h['sentoff2']  = (sentoff2 || []).as_json
       end


       h['referees'] = officials.as_json    if officials
    h
end