Class: Craigslister
- Inherits:
-
Object
- Object
- Craigslister
- Defined in:
- lib/craigslister.rb
Instance Attribute Summary collapse
-
#area ⇒ Object
readonly
Returns the value of attribute area.
-
#high ⇒ Object
readonly
Returns the value of attribute high.
-
#item ⇒ Object
readonly
Returns the value of attribute item.
-
#low ⇒ Object
readonly
Returns the value of attribute low.
Instance Method Summary collapse
-
#initialize(args) ⇒ Craigslister
constructor
A new instance of Craigslister.
- #links ⇒ Object
- #scrape! ⇒ Object
- #url ⇒ Object
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
#area ⇒ Object (readonly)
Returns the value of attribute area.
10 11 12 |
# File 'lib/craigslister.rb', line 10 def area @area end |
#high ⇒ Object (readonly)
Returns the value of attribute high.
10 11 12 |
# File 'lib/craigslister.rb', line 10 def high @high end |
#item ⇒ Object (readonly)
Returns the value of attribute item.
10 11 12 |
# File 'lib/craigslister.rb', line 10 def item @item end |
#low ⇒ Object (readonly)
Returns the value of attribute low.
10 11 12 |
# File 'lib/craigslister.rb', line 10 def low @low end |
Instance Method Details
#links ⇒ Object
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 |
#url ⇒ Object
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 |