Class: Stadiums

Inherits:
Object
  • Object
show all
Defined in:
lib/fbtxt-pp/models/stadiums.rb

Instance Method Summary collapse

Constructor Details

#initializeStadiums

Returns a new instance of Stadiums.



52
53
54
55
# File 'lib/fbtxt-pp/models/stadiums.rb', line 52

def initialize
   @recs    = {}
   @by_city = {}    ## track by cities
end

Instance Method Details

#_add(new_rec) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fbtxt-pp/models/stadiums.rb', line 65

def _add( new_rec )
   rec =  @recs[ new_rec.id ]
   if rec.nil?
       rec = new_rec
       @recs[ new_rec.id ] = new_rec

       city_rec = @by_city[ new_rec.city] ||= []
       city_rec << new_rec
   else
      raise ArgumentError,
         "duplicate stadium records  #{rec.pretty_inspect} == #{new_rec.pretty_inspect}"
   end
end

#add(recs) ⇒ Object



58
59
60
61
62
# File 'lib/fbtxt-pp/models/stadiums.rb', line 58

def add( recs )
   recs.each do |rec|
     _add( Stadium.build(  rec ) )
   end
end

#citiesObject



112
# File 'lib/fbtxt-pp/models/stadiums.rb', line 112

def cities() @by_city.keys; end

#each(sort: true, &blk) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/fbtxt-pp/models/stadiums.rb', line 95

def each( sort: true, &blk )
   recs = if sort
             @recs.values.sort do |l,r|
                res = l.country <=> r.country
                res = l.city    <=> r.city      if res == 0
                res
             end
          else
              @recs.values
          end

   recs.each( &blk )
end

#find!(h) ⇒ Object

Raises:

  • (ArgumentError)


80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fbtxt-pp/models/stadiums.rb', line 80

def find!( h )
    ## quick & dirty verion
     name = h['name']
     city = h['city']

     id  =       slugify( name )
     id += '_' + slugify( city )

     rec =  @recs[ id ]
     raise ArgumentError, "no stadium found for #{h.inspect} using id >#{id}<"  if rec.nil?
     rec
end

#sizeObject



110
# File 'lib/fbtxt-pp/models/stadiums.rb', line 110

def size() @recs.size; end