Class: NbaInfo::Team

Inherits:
Object
  • Object
show all
Defined in:
lib/nba_info/team.rb

Constant Summary collapse

@@nba =
{:east => [], :west => []}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(team_hash) ⇒ Team

Returns a new instance of Team.



7
8
9
10
11
# File 'lib/nba_info/team.rb', line 7

def initialize(team_hash)
  team_hash.each do |key, val|
    self.send "#{key}=", val
  end
end

Instance Attribute Details

#diffObject

Returns the value of attribute diff.



3
4
5
# File 'lib/nba_info/team.rb', line 3

def diff
  @diff
end

#gbObject

Returns the value of attribute gb.



3
4
5
# File 'lib/nba_info/team.rb', line 3

def gb
  @gb
end

#l_tenObject

Returns the value of attribute l_ten.



3
4
5
# File 'lib/nba_info/team.rb', line 3

def l_ten
  @l_ten
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/nba_info/team.rb', line 3

def name
  @name
end

#opp_ppgObject

Returns the value of attribute opp_ppg.



3
4
5
# File 'lib/nba_info/team.rb', line 3

def opp_ppg
  @opp_ppg
end

#placeObject

Returns the value of attribute place.



3
4
5
# File 'lib/nba_info/team.rb', line 3

def place
  @place
end

#ppgObject

Returns the value of attribute ppg.



3
4
5
# File 'lib/nba_info/team.rb', line 3

def ppg
  @ppg
end

#recordObject

Returns the value of attribute record.



3
4
5
# File 'lib/nba_info/team.rb', line 3

def record
  @record
end

#streakObject

Returns the value of attribute streak.



3
4
5
# File 'lib/nba_info/team.rb', line 3

def streak
  @streak
end

#win_pctObject

Returns the value of attribute win_pct.



3
4
5
# File 'lib/nba_info/team.rb', line 3

def win_pct
  @win_pct
end

Class Method Details

.add_statsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/nba_info/team.rb', line 28

def self.add_stats
  self.create
  stats = NbaInfo::Scraper.scrape_stats
  @@nba[:east].each_with_index do |team, i|
    stats[:east][i].each do |key, val|
      team.send "#{key}=", val
    end
  end
  @@nba[:west].each_with_index do |team, i|
    stats[:west][i].each do |key, val|
      team.send "#{key}=", val
    end
  end
  @@nba
end

.createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nba_info/team.rb', line 13

def self.create
  nba = NbaInfo::Scraper.scrape_team
  if @@nba[:east].empty? || @@nba[:west].empty?
    nba[:east].each do |team|
      t = self.new(team)
      @@nba[:east] << t
    end
    nba[:west].each do |team|
      t = self.new(team)
      @@nba[:west] << t
    end
  end
  @@nba
end