Class: Craigslister

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Craigslister

Returns a new instance of Craigslister.



12
13
14
15
16
17
18
# File 'lib/craigslister.rb', line 12

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.



10
11
12
# File 'lib/craigslister.rb', line 10

def area
  @area
end

#highObject (readonly)

Returns the value of attribute high.



10
11
12
# File 'lib/craigslister.rb', line 10

def high
  @high
end

#itemObject (readonly)

Returns the value of attribute item.



10
11
12
# File 'lib/craigslister.rb', line 10

def item
  @item
end

#lowObject (readonly)

Returns the value of attribute low.



10
11
12
# File 'lib/craigslister.rb', line 10

def low
  @low
end

Instance Method Details



24
25
26
# File 'lib/craigslister.rb', line 24

def links
  page_from(url).css('.hdrlnk').map {|link| format_link(link)}
end

#scrape!Object



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

def scrape!
  links.map {|link| item_from(link)}.compact
end

#urlObject



28
29
30
31
32
# File 'lib/craigslister.rb', line 28

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