Created
October 28, 2015 00:24
-
-
Save mharris717/f113ead0f94d6461e529 to your computer and use it in GitHub Desktop.
UFC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'mharris_ext' | |
require 'nokogiri' | |
doc = Nokogiri::HTML(open("fightnight.html")) | |
def fighter_name(node) | |
node.text.gsub("WIN","").gsub("**","").strip | |
end | |
fights = doc.css(".fight") | |
fights.each do |fight| | |
fighters = fight.css(".fighter-name") | |
if fighters.size > 0 | |
loser_node = fight.css(".fighter-name:has(.win.hidden)").first | |
winner_node = (fighters.to_a-[loser_node]).first | |
winner = fighter_name(winner_node) | |
loser = fighter_name(loser_node) | |
puts "#{winner} beat #{loser}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment