Created
August 22, 2011 03:57
-
-
Save ryanhanks/1161624 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
class Feed | |
def page | |
@page ||= get_url | |
end | |
def posts | |
@posts ||= do | |
post_nodes.map do |post_node| | |
build_post(post_node) | |
end | |
end | |
end | |
def post_nodes | |
page.get_xpath(event_node_xpath) | |
end | |
end | |
class MillEvents < Feed | |
def event_node_xpath | |
"//item" | |
end | |
def build_post(post_node) | |
MillPost.new(post_node) | |
end | |
end | |
class Post | |
attr :node | |
def initialize(node) | |
@node = node | |
end | |
def description | |
node.get_xpath(description_xpath) | |
end | |
def title | |
node.get_xpath(title_xpath) | |
end | |
def attributes | |
attributes = {} | |
%w(identifier description title).each do |attr| | |
attributes[attr.to_sym] = self.send(attr) | |
end | |
attributes | |
end | |
end | |
class MillPost < Post | |
def title_xpath | |
"./title" | |
end | |
def identifier | |
# compute an id for node | |
end | |
end | |
%w(mill).each do |venue| | |
get_const("#{venue.camelize}Events").posts.each do |post| | |
if event = Event.find(:one, :conditions => {:venue => venue, :identifier => post.identifier}) | |
# update event | |
else | |
Event.create(post.attributes) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment