Skip to content

Instantly share code, notes, and snippets.

@banister
Forked from danneu/listing_page.rb
Last active December 11, 2015 08:48
Show Gist options
  • Save banister/578e349115718d6f158c to your computer and use it in GitHub Desktop.
Save banister/578e349115718d6f158c to your computer and use it in GitHub Desktop.
class ListingPage
attr_reader :url
def initialize(url)
@url = url
end
def nodes
nodes = []
dom.at_css("#toc_rows").traverse do |node|
nodes << something_node(node)
end
nodes
end
def something_node(node)
case
when node[:class] == "row"
Listing.new(node)
when node[:class]=="ban" && node.name == "h4"
DateBanner.new(node)
end
end
def dom
@dom ||= Nokogiri::HTML(open(url))
end
end
class Node
def initialize(node); @node = node; end
def to_s; "<#{self.class.name}>"; end
end
class Listing < Node
def initialize(node); super; end
end
class DateBanner < Node
def initialize(node); super; end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment