class Craigslister
Creates url from arguments and scrapes
Attributes
area[R]
high[R]
item[R]
low[R]
section[R]
Public Class Methods
new(args)
click to toggle source
# File lib/craigslister/main.rb, line 9 def initialize(args) @area = args.fetch(:area, 'sfbay') @section = args.fetch(:section, 'sss') @item = args[:item] @high = args.fetch(:high, nil) @low = args.fetch(:low, nil) validate_price_range end
Public Instance Methods
posts()
click to toggle source
# File lib/craigslister/main.rb, line 18 def posts LinkScraper.new(url, base_url).posts end
url()
click to toggle source
# File lib/craigslister/main.rb, line 22 def url "#{base_url}/search/#{section}?sort=rel&"\ "#{price_query}query="\ "#{item.downcase.split(' ') * '+'}" end
Private Instance Methods
base_url()
click to toggle source
# File lib/craigslister/main.rb, line 30 def base_url "https://#{area}.craigslist.org" end
price_invalid?()
click to toggle source
# File lib/craigslister/main.rb, line 46 def price_invalid? low && high && low > high end
price_query()
click to toggle source
# File lib/craigslister/main.rb, line 34 def price_query result = '' result += "min_price=#{low}&" if low result += "max_price=#{high}&" if high result end
validate_price_range()
click to toggle source
# File lib/craigslister/main.rb, line 41 def validate_price_range fail(InvalidRangeError, 'Price range is invalid.') if price_invalid? end