Class: Stages

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Stages



14
15
16
# File 'lib/fifadat/tables/stages.rb', line 14

def initialize
   @recs = {}
end

Class Method Details

.read(path) ⇒ Object



6
7
8
9
10
11
# File 'lib/fifadat/tables/stages.rb', line 6

def self.read( path )
    data = read_json_v2( path )
    obj = new
    obj.add( data['Results'] )
    obj
end

Instance Method Details

#_add(new_rec) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/fifadat/tables/stages.rb', line 23

def _add( new_rec )
   rec =  @recs[ new_rec.name ]
   if rec.nil?
       @recs[ new_rec.name ] = new_rec
   else
       raise ArgumentError, "duplicate stage entry: #{new_rec.pretty_inspect}"
   end
end

#add(recs) ⇒ Object

rename to collect - why? why not?



18
19
20
# File 'lib/fifadat/tables/stages.rb', line 18

def add( recs )    ## rename to collect - why? why not?

   recs.each { |h| _add( Stage.build(h)) }
end

#add_matches(matches) ⇒ Object

add match stats



34
35
36
37
38
39
40
# File 'lib/fifadat/tables/stages.rb', line 34

def add_matches( matches )
     matches.each do |m|
       name = desc( m['StageName'] )
       rec  = find!( name )
       rec.count += 1
     end
end

#as_json ⇒ Object



49
50
51
52
53
54
# File 'lib/fifadat/tables/stages.rb', line 49

def as_json(*)
     ## note - sort by seq

     @recs.values.sort do |l,r|
          l.seq <=> r.seq
      end.as_json
end

#find!(name) ⇒ Object

Raises:

  • (ArgumentError)


43
44
45
46
47
# File 'lib/fifadat/tables/stages.rb', line 43

def find!( name )
    rec = @recs[ name ]
    raise ArgumentError, "no stage w/ name >#{name}< found; sorry"  if rec.nil?
    rec
end

#size ⇒ Object



56
# File 'lib/fifadat/tables/stages.rb', line 56

def size() @recs.size; end