Class: Stadium

Inherits:
Object show all
Defined in:
lib/fifadat/models/stadium.rb

Constant Summary collapse

STADIUM_NIL =

dummy/nil record

self.new(  id:      '<nil>',
   name:    '?',
   city:    '?',   ## use nil - why? why not?

   country: '?'    ## use nil - why? why not?

)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, country:, city:, street: nil, id: nil) ⇒ Stadium

Returns a new instance of Stadium.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fifadat/models/stadium.rb', line 42

def initialize( name:, country:, city:,
                 street: nil,
                 id: nil )
   @name = name
   @country = country
   @city = city
   @street = street

    if id.nil?
        ## auto-generate id

        ##  use slug of name plus id_city

        ## add city name

        ##  fix- add   0-9 & dash(-) to name too - why? why not?

        id  =       name.downcase.gsub( /[^a-z]/, '' )
        id += "_" + city.downcase.gsub( /[^a-z]/, '' )
    end
   @id  = id

   ## note - count matches by (home) teams!!!

   @count = Hash.new(0)
end

Instance Attribute Details

#city ⇒ Object (readonly)

Returns the value of attribute city.



40
41
42
# File 'lib/fifadat/models/stadium.rb', line 40

def city
  @city
end

#count ⇒ Object

Returns the value of attribute count.



41
42
43
# File 'lib/fifadat/models/stadium.rb', line 41

def count
  @count
end

#country ⇒ Object (readonly)

Returns the value of attribute country.



40
41
42
# File 'lib/fifadat/models/stadium.rb', line 40

def country
  @country
end

#id ⇒ Object (readonly)

Returns the value of attribute id.



40
41
42
# File 'lib/fifadat/models/stadium.rb', line 40

def id
  @id
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



40
41
42
# File 'lib/fifadat/models/stadium.rb', line 40

def name
  @name
end

#street ⇒ Object (readonly)

Returns the value of attribute street.



40
41
42
# File 'lib/fifadat/models/stadium.rb', line 40

def street
  @street
end

Class Method Details

.build(h) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fifadat/models/stadium.rb', line 5

def self.build( h )
   if h
     ## note - for now stadiums have no ids!!!!!

     ##    check if any ids found

     id         = h['IdStadium']
     id_country = h['IdCountry']

     ## same with city - no ids really in use

     ##    id_city    = h['IdCity']


     name      = desc( h['Name'] )
     city_name = desc( h['CityName'] )

     if name.nil?
       puts "stadium without name:"
       pp h
       exit 1
     end

     ## name, city_name = norm_stadium( name, city_name: city_name )


     new( id: id,
          name: name,
          city: city_name,
          country: id_country,
          street: h['Street']
          )

   else    ## assume nil - dummy record

       STADIUM_NIL
   end
end

Instance Method Details

#==(other) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/fifadat/models/stadium.rb', line 73

def ==(other)
    return false   unless other.is_a?(Stadium)

    ## note - ignore street (and always empty id) for now!!!

    self.name    == other.name &&
    self.city    == other.city &&
    self.country == other.country
end

#as_json ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fifadat/models/stadium.rb', line 83

def as_json(*)
      h = {
            'name'     => name
          }

       h['street']    = street   if street
       h['city']      = city     if city
       h['country']   = country  if country

       h['count'] = count
       h
end