Class: Teams

Inherits:
Object show all
Defined in:
lib/fifadat/tables/teams.rb

Overview

use/change to TeamsRegistry, TeamsLookup, etc

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Teams



5
6
7
# File 'lib/fifadat/tables/teams.rb', line 5

def initialize
   @recs = {}
end

Instance Method Details

#_add(new_rec) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fifadat/tables/teams.rb', line 23

def _add( new_rec )
   rec =  @recs[ new_rec.id ]
   if rec.nil?
       rec = new_rec
       @recs[ new_rec.id ] = new_rec
   else
       ## assert attributes equal - why? why not?
       assert( new_rec == rec,
               "team records NOT matching - #{rec.pretty_inspect} != #{new_rec.pretty_inspect}")
   end
   rec
end

#add_matches(matches) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fifadat/tables/teams.rb', line 9

def add_matches( matches )
   ## note -   if team nil - will (auto-)add nil team (<nil>,?,?,?)
   matches.each do |m|
     rec1 = _add( Team.build( m['Home'] ) )
     rec2 = _add( Team.build( m['Away'] ) )

     stage_name = desc(m['StageName'])
     rec1.count[stage_name] += 1
     rec2.count[stage_name] += 1
   end
end

#as_json(id: false) ⇒ Object

note ignore remove id for now



51
52
53
# File 'lib/fifadat/tables/teams.rb', line 51

def as_json( id: false )  ## note ignore remove id for now
     @recs.values.as_json
end

#find!(h) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
44
45
46
# File 'lib/fifadat/tables/teams.rb', line 37

def find!( h )
   ##  team1 = teams.find( m['HomeTeam'] )
   ##  team2 = teams.find( m['AwayTeam'] )
   ##  use lookup by  "IdTeam": "33161" for now - why? why not?

   ## check for nil - why? why not?
    rec = @recs[ h['IdTeam'] ]
    raise ArgumentError, "team not found using #{h.pretty_inspect}  "  if rec.nil?
    rec
end

#size ⇒ Object



55
# File 'lib/fifadat/tables/teams.rb', line 55

def size() @recs.size; end