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
37
38
39
40
41
42
43
44
45
|
# File 'lib/NBA_info/NBA_info_ex.rb', line 5
def game
x, y, z, w, team_1, start_line_up, s = [], [], [], [], [], [], []
count = 1
doc = Nokogiri.HTML(open('http://scores.espn.go.com/nba/scoreboard'))
time = doc.xpath("//div[@class='game-status']//p")
time.each do |times|
if times.text == 'Final'
x << times.text + ' ' + count.to_s
count += 1
else
x << times.text
end
end
team = doc.xpath("//div[@class='team-capsule']//span")
team.each { |teams| y << teams.text }
score = doc.xpath("//div[@class='mod-content']//ul[@class='score']\
//li[@class='finalScore']")
score.each { |scores| team_1 << scores.text }
player = doc.xpath("//div[@style='display: block']\
//table[@class='game-stat-overview']//tbody//tr//td")
player.each { |p| start_line_up << p.text }
(y.size / 2 - 1).times do |i|
z << y[i * 2] + ' v.s ' + y[i * 2 + 1]
end
(team_1.size / 2 - 1).times do |i|
w << team_1[i * 2] + ' v.s ' + team_1[i * 2 + 1]
end
(start_line_up.size / 5 - 1).times do |i|
s << start_line_up[i * 5] + "\t" + "#{start_line_up[i * 5 + 1]} "\
"#{start_line_up[i * 5 + 2]}" + ' v.s ' + "#{start_line_up[i * 5 + 3]} "\
"#{start_line_up[i * 5 + 4]}"
end
schedule_table_upcoming = Hash[x.zip(z)]
[schedule_table_upcoming, w, s]
end
|