Class: NpbApi::Stats::Team

Inherits:
Object
  • Object
show all
Defined in:
lib/npb-api/stats/team.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row, league, year) ⇒ Team

Returns a new instance of Team.



28
29
30
31
32
# File 'lib/npb-api/stats/team.rb', line 28

def initialize(row, league, year)
  @row = row
  @league = league
  @year = year
end

Instance Attribute Details

#yearObject (readonly)

Returns the value of attribute year.



26
27
28
# File 'lib/npb-api/stats/team.rb', line 26

def year
  @year
end

Class Method Details

.list(league, year) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/npb-api/stats/team.rb', line 8

def self.list(league, year)
  regular_reague = source(league, year).css('table.stdtblSubmain')[0]
  regular_reague.css('tr[align="center"]').each_with_object([]) do |row, arr|
    next if row.css('td.stdTeam').empty? # 行にチーム名が含まれていなかったらスキップ
    arr << new(row, league, year)
  end
end

Instance Method Details

#drawsObject



59
60
61
# File 'lib/npb-api/stats/team.rb', line 59

def draws
  @row.css('td.stdscore')[3].text.to_i
end

#gamesObject



47
48
49
# File 'lib/npb-api/stats/team.rb', line 47

def games
  @row.css('td.stdscore')[0].text.to_i
end

#games_behindObject



67
68
69
# File 'lib/npb-api/stats/team.rb', line 67

def games_behind
  @row.css('td.stdscore')[5].text
end

#leagueObject



34
35
36
37
38
39
40
41
# File 'lib/npb-api/stats/team.rb', line 34

def league
  case @league
  when 'c' then 'central'
  when 'p' then 'pacific'
  when 'e' then 'eastern'
  when 'w' then 'western'
  end
end

#losesObject



55
56
57
# File 'lib/npb-api/stats/team.rb', line 55

def loses
  @row.css('td.stdscore')[2].text.to_i
end

#teamObject



43
44
45
# File 'lib/npb-api/stats/team.rb', line 43

def team
  @row.css('td.stdTeam').text.gsub(/ /, '')
end

#winning_percentageObject



63
64
65
# File 'lib/npb-api/stats/team.rb', line 63

def winning_percentage
  @row.css('td.stdscore')[4].text.to_f
end

#winsObject



51
52
53
# File 'lib/npb-api/stats/team.rb', line 51

def wins
  @row.css('td.stdscore')[1].text.to_i
end