lib/sportdb/formats/structs/match.rb in sportdb-formats-0.4.0 vs lib/sportdb/formats/structs/match.rb in sportdb-formats-1.0.0
- old
+ new
@@ -4,12 +4,28 @@
module Import
class Match
- def self.create( **kwargs ) ## keep using create why? why not?
- new.update( kwargs )
+ attr_reader :date,
+ :team1, :team2, ## todo/fix: use team1_name, team2_name or similar - for compat with db activerecord version? why? why not?
+ :score1, :score2, ## full time
+ :score1i, :score2i, ## half time (first (i) part)
+ :score1et, :score2et, ## extra time
+ :score1p, :score2p, ## penalty
+ :score1agg, :score2agg, ## full time (all legs) aggregated
+ :winner, # return 1,2,0 1 => team1, 2 => team2, 0 => draw/tie
+ :round, ## todo/fix: use round_num or similar - for compat with db activerecord version? why? why not?
+ :leg, ## e.g. '1','2','3','replay', etc. - use leg for marking **replay** too - keep/make leg numeric?! - why? why not?
+ :stage,
+ :group,
+ :conf1, :conf2, ## special case for mls e.g. conference1, conference2 (e.g. west, east, central)
+ :country1, :country2, ## special case for champions league etc. - uses FIFA country code
+ :comments
+
+ def initialize( **kwargs )
+ update( kwargs ) unless kwargs.empty?
end
def update( **kwargs )
## note: check with has_key? because value might be nil!!!
@date = kwargs[:date] if kwargs.has_key? :date
@@ -29,45 +45,72 @@
@stage = kwargs[:stage] if kwargs.has_key? :stage
@leg = kwargs[:leg] if kwargs.has_key? :leg
@group = kwargs[:group] if kwargs.has_key? :group
@comments = kwargs[:comments] if kwargs.has_key? :comments
+ 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
- @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 = 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 = 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
+ @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
- ## 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 = 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
- @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
+ ## 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 "*** missing scores for match:"
+ puts "** WARN: missing scores for match:"
pp kwargs
## exit 1
end
## todo/fix: auto-calculate winner
@@ -87,31 +130,9 @@
end
self ## note - MUST return self for chaining
end
-
- attr_reader :date,
- :team1, :team2, ## todo/fix: use team1_name, team2_name or similar - for compat with db activerecord version? why? why not?
- :score1, :score2, ## full time
- :score1i, :score2i, ## half time (first (i) part)
- :score1et, :score2et, ## extra time
- :score1p, :score2p, ## penalty
- :score1agg, :score2agg, ## full time (all legs) aggregated
- :winner, # return 1,2,0 1 => team1, 2 => team2, 0 => draw/tie
- :round, ## todo/fix: use round_num or similar - for compat with db activerecord version? why? why not?
- :leg, ## e.g. '1','2','3','replay', etc. - use leg for marking **replay** too - keep/make leg numeric?! - why? why not?
- :stage,
- :group,
- :conf1, :conf2, ## special case for mls e.g. conference1, conference2 (e.g. west, east, central)
- :country1, :country2, ## special case for champions league etc. - uses FIFA country code
- :comments
-
-
-
- def initialize( **kwargs )
- update( kwargs ) unless kwargs.empty?
- end
def over?() true; end ## for now all matches are over - in the future check date!!!
def complete?() true; end ## for now all scores are complete - in the future check scores; might be missing - not yet entered