-
-
Save banister/578e349115718d6f158c 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 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