Class: Craigslister

Inherits:
Object
  • Object
show all
Defined in:
lib/craigslister/craigslister.rb

Overview

Creates url from arguments and scrapes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Craigslister

Returns a new instance of Craigslister.



9
10
11
12
13
14
15
# File 'lib/craigslister/craigslister.rb', line 9

def initialize(args)
  @area    = args.fetch(:area, 'sfbay')
  @item    = args[:item]
  @high    = args.fetch(:high, nil)
  @low     = args.fetch(:low, nil)
  validate_price_range
end

Instance Attribute Details

#areaObject (readonly)

Returns the value of attribute area.



7
8
9
# File 'lib/craigslister/craigslister.rb', line 7

def area
  @area
end

#highObject (readonly)

Returns the value of attribute high.



7
8
9
# File 'lib/craigslister/craigslister.rb', line 7

def high
  @high
end

#itemObject (readonly)

Returns the value of attribute item.



7
8
9
# File 'lib/craigslister/craigslister.rb', line 7

def item
  @item
end

#lowObject (readonly)

Returns the value of attribute low.



7
8
9
# File 'lib/craigslister/craigslister.rb', line 7

def low
  @low
end

Instance Method Details



21
22
23
# File 'lib/craigslister/craigslister.rb', line 21

def links
  scraper.links
end

#scrapeObject



17
18
19
# File 'lib/craigslister/craigslister.rb', line 17

def scrape
  scraper.scrape
end

#urlObject



25
26
27
28
29
# File 'lib/craigslister/craigslister.rb', line 25

def url
  "#{base_url}/search/sss?sort=rel&"\
  "#{price_query}query="\
  "#{item.downcase.split(' ') * '+'}"
end