class LinkScraper
Scrapes links and feeds them to PostScraper
Attributes
base_url[R]
url[R]
Public Class Methods
new(url, base_url)
click to toggle source
# File lib/craigslister/link_scraper.rb, line 3 def initialize(url, base_url) @url = url @base_url = base_url end
Public Instance Methods
links()
click to toggle source
# File lib/craigslister/link_scraper.rb, line 8 def links header_link.map { |link| format_link(link['href']) } end
posts()
click to toggle source
# File lib/craigslister/link_scraper.rb, line 12 def posts links.flat_map { |link| post_from(link) } end
Private Instance Methods
format_link(link)
click to toggle source
# File lib/craigslister/link_scraper.rb, line 32 def format_link(link) if link.match(/\w+\.craig/) 'https:' + link else base_url + link end end
header_link()
click to toggle source
# File lib/craigslister/link_scraper.rb, line 28 def header_link page_from(url).css('.hdrlnk') end
page_from(url)
click to toggle source
# File lib/craigslister/link_scraper.rb, line 20 def page_from(url) Nokogiri::HTML(open(url)) end
post_from(link)
click to toggle source
# File lib/craigslister/link_scraper.rb, line 24 def post_from(link) PostScraper.new(page_from(link), link).new_post end