Class: Arbitrage::Scraper
- Inherits:
-
Object
- Object
- Arbitrage::Scraper
- Defined in:
- lib/arbitrage/Scraper.rb
Instance Attribute Summary collapse
-
#buy_options ⇒ Object
Returns the value of attribute buy_options.
-
#product ⇒ Object
Returns the value of attribute product.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #buy_options_menu(doc) ⇒ Object
- #craigslist_query ⇒ Object
- #craigslist_search_url(url, query) ⇒ Object
- #create_index_url ⇒ Object
- #create_product_list ⇒ Object
- #display_buy_options ⇒ Object
Instance Attribute Details
#buy_options ⇒ Object
Returns the value of attribute buy_options.
2 3 4 |
# File 'lib/arbitrage/Scraper.rb', line 2 def @buy_options end |
#product ⇒ Object
Returns the value of attribute product.
2 3 4 |
# File 'lib/arbitrage/Scraper.rb', line 2 def product @product end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/arbitrage/Scraper.rb', line 2 def url @url end |
Instance Method Details
#buy_options_menu(doc) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/arbitrage/Scraper.rb', line 22 def (doc) self. = {} doc.css('.row').each_with_index do |row, i| if i < 11 self.["#{i+1}".to_s] = { name: (row.css('.hdrlnk').text), price: (row.css('.l2 .price').text), url:"#{self.url}mod/#{(row.css('.pl a')[0]['data-id'])}.html" } end end end |
#craigslist_query ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/arbitrage/Scraper.rb', line 41 def craigslist_query query = self.product.name.split(" ") if query.size > 1 query= query.join("%20") else query= query.join end self.product.query = query end |
#craigslist_search_url(url, query) ⇒ Object
51 52 53 |
# File 'lib/arbitrage/Scraper.rb', line 51 def craigslist_search_url(url,query) "#{url}search/sss?query=#{query}&sort=rel" end |
#create_index_url ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/arbitrage/Scraper.rb', line 4 def create_index_url csv_data = File.read('rsc/clzips.csv') rows = csv_data.split("\n") people = rows.collect do |row| data = row.split(",") if data[1] == self.product.zipcode self.url=data[0] end end end |
#create_product_list ⇒ Object
15 16 17 18 19 20 |
# File 'lib/arbitrage/Scraper.rb', line 15 def create_product_list html = open(craigslist_search_url(self.url,craigslist_query)) doc = Nokogiri::HTML(html) (doc) end |
#display_buy_options ⇒ Object
35 36 37 38 39 |
# File 'lib/arbitrage/Scraper.rb', line 35 def self..each do |key, value| puts "#{key}.#{value[:name]} for #{value[:price]}" end end |