Created
April 6, 2011 01:07
-
-
Save jph/904931 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
require 'ostruct' | |
class LineStatus | |
def initialize | |
statuses = [] | |
@doc = Nokogiri::HTML(open('http://www.metrotrains.com.au/')) | |
@doc.css("table.serviceUpdates .col2 div.good, table.serviceUpdates .col2 div.good").each do |div| | |
statuses << div.content.strip.gsub(/\t/, '') | |
end | |
@doc.css("table.serviceUpdates .col1 a").each_with_index do |line_name, index| | |
line_info = OpenStruct.new | |
line_info.status = statuses[index].match('Good service') ? 'not fucked' : 'fucked' | |
line_info.delays = delays(index) | |
line_info.cancellations = cancellations(index) | |
line_name = "#{line_name.content.downcase.gsub(' ','_')}" | |
self.instance_variable_set("@#{line_name}", line_info) | |
self.class.send(:define_method, line_name, proc{ self.instance_variable_get("@#{line_name}") }) | |
end | |
end | |
def delays(line_index) | |
'Currently no delays' | |
end | |
def cancellations(line_index) | |
'Currently no cancellations' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment