Permalink
Browse files

Change search method for compatible with online-games

  • Loading branch information...
1 parent c14cdd3 commit b68ae27b8e3d0faf9847f09d375cbdd4b558f141 @sharipov-ru sharipov-ru committed Apr 5, 2011
Showing with 11 additions and 13 deletions.
  1. +11 −13 espn_nhl_parser.rb
View
@@ -7,27 +7,25 @@
doc = Nokogiri::HTML(open(url))
doc.css("div.game-header").each do |gametable| # gametable - html table of current game
- unless gametable.at_css("tr.loser a").nil? # if game not started then skip
- loser = gametable.at_css("tr.loser a").text
- winner = gametable.at_css("tr.winner a").text
- winner_place = gametable.at_css("tr.winner")[:id].scan(/home|away/)
+ unless gametable.at_css("tr td div a").nil? # if game not started then skip
+ teams = []
score = []
+ gametable.css("tr td div a").each do |team_name| # Searching two team names (for away and home teams)
+ teams << team_name.text
+ end
+ away, home = teams
gametable.css("td.team-score").each do |team_score| # Need to find two scores per game (for away and home teams)
score << team_score.text
- end
- result = "#{score[1]}:#{score[0]}" # Away team - Home team
- game_info = gametable.at_css("ul.game-info li").text.scan(/OT|SO/).to_s
- if winner_place.to_s == "home"
- game = "#{winner}-#{loser} #{result} #{game_info}"
- else
- game = "#{loser}-#{winner} #{result} #{game_info}"
end
+ result = "#{score[1]}:#{score[0]}" # Away team - Home team
+ game_info = gametable.at_css("ul.game-info li").text
+ game = "#{home}-#{away} #{result} #{game_info}"
games << game
- end # unless`
+ end # unless
end # each
if games.empty?
- puts "Today no played games"
+ puts "Today no games"
else
puts games
end

0 comments on commit b68ae27

Please sign in to comment.