Class: Team

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

Constant Summary collapse

TEAM_NIL =

shared dummy/nil record

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, id: nil, code: nil, country: nil) ⇒ Team



27
28
29
30
31
32
33
34
35
36
# File 'lib/fifadat/models/team.rb', line 27

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

    @count = Hash.new(0)   ## match (reference/usage) count(er) by stage (name)!!
end

Instance Attribute Details

#code ⇒ Object (readonly)

Returns the value of attribute code.



23
24
25
# File 'lib/fifadat/models/team.rb', line 23

def code
  @code
end

#count ⇒ Object

Returns the value of attribute count.



25
26
27
# File 'lib/fifadat/models/team.rb', line 25

def count
  @count
end

#country ⇒ Object (readonly)

Returns the value of attribute country.



23
24
25
# File 'lib/fifadat/models/team.rb', line 23

def country
  @country
end

#id ⇒ Object (readonly)

Returns the value of attribute id.



23
24
25
# File 'lib/fifadat/models/team.rb', line 23

def id
  @id
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/fifadat/models/team.rb', line 23

def name
  @name
end

Class Method Details

.build(h) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fifadat/models/team.rb', line 6

def self.build( h )
   if h
      name = desc( h['TeamName'] )
      ##  name = norm_team( name )

      new( id:      h['IdTeam'],
           name:    name,
           code:    h['Abbreviation'],
           country: h['IdCountry']    ## change to cc (country code) - why? why not?
         )
   else    ## assume nil - dummy record
      TEAM_NIL
   end
end

Instance Method Details

#==(other) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/fifadat/models/team.rb', line 62

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

    ## check code too - why? why not?
    ##   note - ignore code for now
    self.id      == other.id &&
    self.name    == other.name &&
    self.country == other.country
end

#as_json ⇒ Object



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

def as_json(*)
      h = {
            'name'    => name,
            'code'    => code,
            'country' => country,
            'count'   => count,
            'id'      => id
          }
      h
end