Class: Sports::TeamUsage

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

Defined Under Namespace

Classes: TeamUsageLine

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ TeamUsage

Returns a new instance of TeamUsage.



24
25
26
# File 'lib/sportdb/structs/structs/team_usage.rb', line 24

def initialize( opts={} )
  @lines = {}   # StandingsLines cached by team name/key
end

Instance Method Details

#to_aObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sportdb/structs/structs/team_usage.rb', line 37

def to_a
  ## return lines; sort

  # build array from hash
  ary = []
  @lines.each do |k,v|
    ary << v
  end

  ## for now sort just by name (a-z)
  ary.sort! do |l,r|
    ## note: reverse order (thus, change l,r to r,l)
    l.team <=> r.team
  end

  ary
end

#update(matches, season: '?', level: nil) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/sportdb/structs/structs/team_usage.rb', line 29

def update( matches, season: '?', level: nil )
  ## convenience - update all matches at once
  matches.each_with_index do |match,i| # note: index(i) starts w/ zero (0)
    update_match( match, season: season, level: level )
  end
  self  # note: return self to allow chaining
end