Created
August 29, 2009 18:26
-
-
Save jeffrydegrande/177610 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'rubygems' | |
require 'open-uri' | |
require 'nokogiri' | |
require 'icalendar' | |
require 'date' | |
class RailsSummit | |
include Icalendar | |
def initialize | |
@doc = Nokogiri::HTML(open('http://www.railssummit.com.br/pt-BR/schedule'), nil, 'UTF-8') | |
@cal = Calendar.new | |
parse! | |
end | |
def parse! | |
@doc.css('table.programacao').each_with_index do |day, index| | |
date = Date.parse("2009/10/#{13 + index}") | |
day.search('tr').each do |tr| | |
cells = tr.search('td') | |
next if cells.count == 0 | |
time = cells.shift.content.strip | |
first, second = cells | |
if first['colspan'].to_i == 2 | |
add_event(date, time, first.content.strip) | |
else | |
add_event(date, time, "Sala A: #{first.content.strip}" ) | |
add_event(date, time, "Sala B: #{second.content.strip}" ) | |
end | |
end | |
end | |
end | |
def to_s | |
@cal.to_ical | |
end | |
private | |
def add_event(date, time, summary) | |
from, junk, to = time.split | |
event = Event.new | |
event.start = DateTime.parse("#{date} #{from}") | |
event.end = DateTime.parse("#{date} #{to}") | |
event.summary = summary | |
event.description = summary | |
@cal.add_event(event) | |
end | |
end | |
puts RailsSummit.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment