Class: Sports::Match
- Inherits:
-
Object
- Object
- Sports::Match
- Defined in:
- lib/sportdb/structs/match.rb
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
-
#conf1 ⇒ Object
readonly
Returns the value of attribute conf1.
-
#conf2 ⇒ Object
readonly
Returns the value of attribute conf2.
-
#country1 ⇒ Object
readonly
Returns the value of attribute country1.
-
#country2 ⇒ Object
readonly
Returns the value of attribute country2.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#goals ⇒ Object
todo/fix: make goals like all other attribs!!.
-
#ground ⇒ Object
readonly
Returns the value of attribute ground.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#league ⇒ Object
readonly
Returns the value of attribute league.
-
#leg ⇒ Object
readonly
Returns the value of attribute leg.
-
#num ⇒ Object
readonly
Returns the value of attribute num.
-
#round ⇒ Object
readonly
Returns the value of attribute round.
-
#score1 ⇒ Object
readonly
Returns the value of attribute score1.
-
#score1agg ⇒ Object
readonly
Returns the value of attribute score1agg.
-
#score1et ⇒ Object
readonly
Returns the value of attribute score1et.
-
#score1i ⇒ Object
readonly
Returns the value of attribute score1i.
-
#score1p ⇒ Object
readonly
Returns the value of attribute score1p.
-
#score2 ⇒ Object
readonly
Returns the value of attribute score2.
-
#score2agg ⇒ Object
readonly
Returns the value of attribute score2agg.
-
#score2et ⇒ Object
readonly
Returns the value of attribute score2et.
-
#score2i ⇒ Object
readonly
Returns the value of attribute score2i.
-
#score2p ⇒ Object
readonly
Returns the value of attribute score2p.
-
#stage ⇒ Object
readonly
Returns the value of attribute stage.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#team1 ⇒ Object
readonly
Returns the value of attribute team1.
-
#team2 ⇒ Object
readonly
Returns the value of attribute team2.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#winner ⇒ Object
readonly
Returns the value of attribute winner.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#complete? ⇒ Boolean
for now all scores are complete - in the future check scores; might be missing - not yet entered.
-
#initialize(**kwargs) ⇒ Match
constructor
A new instance of Match.
-
#over? ⇒ Boolean
for now all matches are over - in the future check date!!!.
- #score ⇒ Object
- #update(**kwargs) ⇒ Object
Constructor Details
#initialize(**kwargs) ⇒ Match
Returns a new instance of Match.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sportdb/structs/match.rb', line 30 def initialize( **kwargs ) @score1 = @score2 = nil ## full time @score1i = @score2i = nil ## half time (first (i) part) @score1et = @score2et = nil ## extra time @score1p = @score2p = nil ## penalty @score1agg = @score2agg = nil ## full time (all legs) aggregated update( **kwargs ) unless kwargs.empty? end |
Instance Attribute Details
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def comments @comments end |
#conf1 ⇒ Object (readonly)
Returns the value of attribute conf1.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def conf1 @conf1 end |
#conf2 ⇒ Object (readonly)
Returns the value of attribute conf2.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def conf2 @conf2 end |
#country1 ⇒ Object (readonly)
Returns the value of attribute country1.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def country1 @country1 end |
#country2 ⇒ Object (readonly)
Returns the value of attribute country2.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def country2 @country2 end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def date @date end |
#goals ⇒ Object
todo/fix: make goals like all other attribs!!
28 29 30 |
# File 'lib/sportdb/structs/match.rb', line 28 def goals @goals end |
#ground ⇒ Object (readonly)
Returns the value of attribute ground.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def ground @ground end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def group @group end |
#league ⇒ Object (readonly)
Returns the value of attribute league.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def league @league end |
#leg ⇒ Object (readonly)
Returns the value of attribute leg.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def leg @leg end |
#num ⇒ Object (readonly)
Returns the value of attribute num.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def num @num end |
#round ⇒ Object (readonly)
Returns the value of attribute round.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def round @round end |
#score1 ⇒ Object (readonly)
Returns the value of attribute score1.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def score1 @score1 end |
#score1agg ⇒ Object (readonly)
Returns the value of attribute score1agg.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def score1agg @score1agg end |
#score1et ⇒ Object (readonly)
Returns the value of attribute score1et.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def score1et @score1et end |
#score1i ⇒ Object (readonly)
Returns the value of attribute score1i.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def score1i @score1i end |
#score1p ⇒ Object (readonly)
Returns the value of attribute score1p.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def score1p @score1p end |
#score2 ⇒ Object (readonly)
Returns the value of attribute score2.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def score2 @score2 end |
#score2agg ⇒ Object (readonly)
Returns the value of attribute score2agg.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def score2agg @score2agg end |
#score2et ⇒ Object (readonly)
Returns the value of attribute score2et.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def score2et @score2et end |
#score2i ⇒ Object (readonly)
Returns the value of attribute score2i.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def score2i @score2i end |
#score2p ⇒ Object (readonly)
Returns the value of attribute score2p.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def score2p @score2p end |
#stage ⇒ Object (readonly)
Returns the value of attribute stage.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def stage @stage end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def status @status end |
#team1 ⇒ Object (readonly)
Returns the value of attribute team1.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def team1 @team1 end |
#team2 ⇒ Object (readonly)
Returns the value of attribute team2.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def team2 @team2 end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def time @time end |
#winner ⇒ Object (readonly)
Returns the value of attribute winner.
7 8 9 |
# File 'lib/sportdb/structs/match.rb', line 7 def winner @winner end |
Instance Method Details
#as_json ⇒ Object
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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/sportdb/structs/match.rb', line 183 def as_json ## data = {} ## check round if @round data[:round ] = if round.is_a?( Integer ) "Matchday #{@round}" else ## assume string @round end end data[:num] = @num if @num if @date ## assume 2020-09-19 date format!! data[:date] = @date.is_a?( String ) ? @date : @date.strftime('%Y-%m-%d') data[:time] = @time if @time end data[:team1] = @team1.is_a?( String ) ? @team1 : @team1.name data[:team2] = @team2.is_a?( String ) ? @team2 : @team2.name data[:score] = {} data[:score][:ht] = [@score1i, @score2i] if @score1i && @score2i data[:score][:ft] = [@score1, @score2] if @score1 && @score2 data[:score][:et] = [@score1et, @score2et] if @score1et && @score2et data[:score][:p] = [@score1p, @score2p] if @score1p && @score2p data[:group] = @group if @group =begin "round": "Spieltag 1", "date": "2020-09-19", "team1": "Eintracht Frankfurt", "team2": "Arminia Bielefeld", "score": { "ft": [ 1, 1 ] } =end data end |
#complete? ⇒ Boolean
for now all scores are complete - in the future check scores; might be missing - not yet entered
161 |
# File 'lib/sportdb/structs/match.rb', line 161 def complete?() true; end |
#over? ⇒ Boolean
for now all matches are over - in the future check date!!!
160 |
# File 'lib/sportdb/structs/match.rb', line 160 def over?() true; end |
#score ⇒ Object
164 165 166 167 168 169 |
# File 'lib/sportdb/structs/match.rb', line 164 def score Score.new( @score1i, @score2i, ## half time (first (i) part) @score1, @score2, ## full time @score1et, @score2et, ## extra time @score1p, @score2p ) ## penalty end |
#update(**kwargs) ⇒ Object
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 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 152 153 154 155 156 |
# File 'lib/sportdb/structs/match.rb', line 42 def update( **kwargs ) @num = kwargs[:num] if kwargs.has_key?( :num ) ## note: check with has_key? because value might be nil!!! @date = kwargs[:date] if kwargs.has_key?( :date ) @time = kwargs[:time] if kwargs.has_key?( :time ) ## todo/fix: use team1_name, team2_name or similar - for compat with db activerecord version? why? why not? @team1 = kwargs[:team1] if kwargs.has_key?( :team1 ) @team2 = kwargs[:team2] if kwargs.has_key?( :team2 ) @conf1 = kwargs[:conf1] if kwargs.has_key?( :conf1 ) @conf2 = kwargs[:conf2] if kwargs.has_key?( :conf2 ) @country1 = kwargs[:country1] if kwargs.has_key?( :country1 ) @country2 = kwargs[:country2] if kwargs.has_key?( :country2 ) ## note: round is a string!!! e.g. '1', '2' for matchday or 'Final', 'Semi-final', etc. ## todo: use to_s - why? why not? @round = kwargs[:round] if kwargs.has_key?( :round ) @stage = kwargs[:stage] if kwargs.has_key?( :stage ) @leg = kwargs[:leg] if kwargs.has_key?( :leg ) @group = kwargs[:group] if kwargs.has_key?( :group ) @status = kwargs[:status] if kwargs.has_key?( :status ) @comments = kwargs[:comments] if kwargs.has_key?( :comments ) @league = kwargs[:league] if kwargs.has_key?( :league ) @ground = kwargs[:ground] if kwargs.has_key?( :ground ) if kwargs.has_key?( :score ) ## check all-in-one score struct for convenience!!! score = kwargs[:score] if score.nil? ## reset all score attribs to nil!! @score1 = nil @score1i = nil @score1et = nil @score1p = nil ## @score1agg = nil @score2 = nil @score2i = nil @score2et = nil @score2p = nil ## @score2agg = nil else @score1 = score.score1 @score1i = score.score1i @score1et = score.score1et @score1p = score.score1p ## @score1agg = score.score1agg @score2 = score.score2 @score2i = score.score2i @score2et = score.score2et @score2p = score.score2p ## @score2agg = score.score2agg end else @score1 = kwargs[:score1] if kwargs.has_key?( :score1 ) @score1i = kwargs[:score1i] if kwargs.has_key?( :score1i ) @score1et = kwargs[:score1et] if kwargs.has_key?( :score1et ) @score1p = kwargs[:score1p] if kwargs.has_key?( :score1p ) @score1agg = kwargs[:score1agg] if kwargs.has_key?( :score1agg ) @score2 = kwargs[:score2] if kwargs.has_key?( :score2 ) @score2i = kwargs[:score2i] if kwargs.has_key?( :score2i ) @score2et = kwargs[:score2et] if kwargs.has_key?( :score2et ) @score2p = kwargs[:score2p] if kwargs.has_key?( :score2p ) @score2agg = kwargs[:score2agg] if kwargs.has_key?( :score2agg ) ## note: (always) (auto-)convert scores to integers @score1 = @score1.to_i if @score1 @score1i = @score1i.to_i if @score1i @score1et = @score1et.to_i if @score1et @score1p = @score1p.to_i if @score1p @score1agg = @score1agg.to_i if @score1agg @score2 = @score2.to_i if @score2 @score2i = @score2i.to_i if @score2i @score2et = @score2et.to_i if @score2et @score2p = @score2p.to_i if @score2p @score2agg = @score2agg.to_i if @score2agg end ## todo/fix: ## gr-greece/2014-15/G1.csv: ## G1,10/05/15,Niki Volos,OFI,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ## ## for now score1 and score2 must be present ## if @score1.nil? || @score2.nil? ## puts "** WARN: missing scores for match:" ## pp kwargs ## ## exit 1 ## end ## todo/fix: auto-calculate winner # return 1,2,0 1 => team1, 2 => team2, 0 => draw/tie ### calculate winner - use 1,2,0 ## ## move winner calc to score class - why? why not? if @score1 && @score2 if @score1 > @score2 @winner = 1 elsif @score2 > @score1 @winner = 2 elsif @score1 == @score2 @winner = 0 else end else @winner = nil # unknown / undefined end self ## note - MUST return self for chaining end |