Skip to content

Instantly share code, notes, and snippets.

@jph
Created April 6, 2011 01:07
Show Gist options
  • Save jph/904931 to your computer and use it in GitHub Desktop.
Save jph/904931 to your computer and use it in GitHub Desktop.
#!/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