Class: SportDb::StandingsHelper::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/calc.rb

Overview

todo:

add team_id to struct - why? why not?  - saves a db lookup?

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStats

Returns a new instance of Stats.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sportdb/calc.rb', line 26

def initialize
  @pos           = nil    # use 0? why? why not?
  @played        = 0
  @won           = 0
  @lost          = 0
  @drawn         = 0
  @goals_for     = 0
  @goals_against = 0
  @pts           = 0
  @recs          = 0
  # note: appearances (event) count  or similar
  #   is recs counter (number of (stats) records)
end

Instance Attribute Details

#drawnObject

fix/todo: change/rename :pos to :rank



22
23
24
# File 'lib/sportdb/calc.rb', line 22

def drawn
  @drawn
end

#goals_againstObject

fix/todo: change/rename :pos to :rank



22
23
24
# File 'lib/sportdb/calc.rb', line 22

def goals_against
  @goals_against
end

#goals_forObject

fix/todo: change/rename :pos to :rank



22
23
24
# File 'lib/sportdb/calc.rb', line 22

def goals_for
  @goals_for
end

#lostObject

fix/todo: change/rename :pos to :rank



22
23
24
# File 'lib/sportdb/calc.rb', line 22

def lost
  @lost
end

#playedObject

fix/todo: change/rename :pos to :rank



22
23
24
# File 'lib/sportdb/calc.rb', line 22

def played
  @played
end

#posObject

fix/todo: change/rename :pos to :rank



22
23
24
# File 'lib/sportdb/calc.rb', line 22

def pos
  @pos
end

#ptsObject

fix/todo: change/rename :pos to :rank



22
23
24
# File 'lib/sportdb/calc.rb', line 22

def pts
  @pts
end

#recsObject

fix/todo: change/rename :pos to :rank



22
23
24
# File 'lib/sportdb/calc.rb', line 22

def recs
  @recs
end

#wonObject

fix/todo: change/rename :pos to :rank



22
23
24
# File 'lib/sportdb/calc.rb', line 22

def won
  @won
end

Instance Method Details

#add(rec) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sportdb/calc.rb', line 40

def add( rec )
  ### fix: add plus + operator too!
  
  # note: will NOT update/add pos (ranking)
  self.played        += rec.played
  self.won           += rec.won
  self.lost          += rec.lost
  self.drawn         += rec.drawn
  self.goals_for     += rec.goals_for
  self.goals_against += rec.goals_against
  self.pts           += rec.pts
  self.recs          += rec.recs

  self # return self stats rec
end