class PostScraper
Scrapes craigslist posts and packages data in Post
objects
Attributes
link[R]
page[R]
Public Class Methods
new(page, link)
click to toggle source
# File lib/craigslister/post_scraper.rb, line 3 def initialize(page, link) @page = page @link = link end
Public Instance Methods
new_post()
click to toggle source
# File lib/craigslister/post_scraper.rb, line 8 def new_post Post.new(post_params) end
Private Instance Methods
description()
click to toggle source
# File lib/craigslister/post_scraper.rb, line 50 def description page.at('section#postingbody').text end
image()
click to toggle source
# File lib/craigslister/post_scraper.rb, line 31 def image image = page.at('img') image ? image['src'] : '' end
location()
click to toggle source
# File lib/craigslister/post_scraper.rb, line 45 def location location = posting_title.at('small') location ? location.text.gsub(/ ?[\(\)]/, '') : '' end
post_params()
click to toggle source
# File lib/craigslister/post_scraper.rb, line 20 def post_params { image: image, title: title, price: price, location: location, description: description, url: link } end
posting_title()
click to toggle source
# File lib/craigslister/post_scraper.rb, line 16 def posting_title page.at('span.postingtitletext') end
price()
click to toggle source
# File lib/craigslister/post_scraper.rb, line 40 def price price = posting_title.at('span.price') price ? price.text.gsub(/\$/, '').to_i : 0 end
title()
click to toggle source
# File lib/craigslister/post_scraper.rb, line 36 def title posting_title.text.gsub(/ ?- ?\$\d+ ?\(.+\)/, '') end