Class: PopularDeals::NewDeals
- Inherits:
-
Object
- Object
- PopularDeals::NewDeals
- Defined in:
- lib/popular_deals/newdeals.rb
Instance Attribute Summary collapse
-
#deal_rating ⇒ Object
Returns the value of attribute deal_rating.
-
#discription ⇒ Object
Returns the value of attribute discription.
-
#name ⇒ Object
Returns the value of attribute name.
-
#posted ⇒ Object
Returns the value of attribute posted.
-
#price ⇒ Object
Returns the value of attribute price.
-
#purchase ⇒ Object
Returns the value of attribute purchase.
-
#purchase_link ⇒ Object
Returns the value of attribute purchase_link.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .deal_page(base_url, input, product_url) ⇒ Object
- .open_deal_page(base_url, input) ⇒ Object
- .scrap_slickdeals(base_url) ⇒ Object
Instance Attribute Details
#deal_rating ⇒ Object
Returns the value of attribute deal_rating.
4 5 6 |
# File 'lib/popular_deals/newdeals.rb', line 4 def end |
#discription ⇒ Object
Returns the value of attribute discription.
4 5 6 |
# File 'lib/popular_deals/newdeals.rb', line 4 def discription @discription end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/popular_deals/newdeals.rb', line 4 def name @name end |
#posted ⇒ Object
Returns the value of attribute posted.
4 5 6 |
# File 'lib/popular_deals/newdeals.rb', line 4 def posted @posted end |
#price ⇒ Object
Returns the value of attribute price.
4 5 6 |
# File 'lib/popular_deals/newdeals.rb', line 4 def price @price end |
#purchase ⇒ Object
Returns the value of attribute purchase.
4 5 6 |
# File 'lib/popular_deals/newdeals.rb', line 4 def purchase @purchase end |
#purchase_link ⇒ Object
Returns the value of attribute purchase_link.
4 5 6 |
# File 'lib/popular_deals/newdeals.rb', line 4 def purchase_link @purchase_link end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/popular_deals/newdeals.rb', line 4 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/popular_deals/newdeals.rb', line 4 def url @url end |
Class Method Details
.deal_page(base_url, input, product_url) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/popular_deals/newdeals.rb', line 33 def self.deal_page(base_url, input, product_url) self.open_deal_page(base_url, input) deal = {} html = open(@product_url) doc = Nokogiri::HTML(html) data = doc.text.strip deal[:name] = doc.css("h1").text.strip deal[:discription] = doc.css(".textDescription").text.strip if doc.at_css("a#largeBuyNow").nil? deal[:purchase] = @product_url else deal[:purchase] = doc.at_css("a#largeBuyNow").attr("href") end deal end |
.open_deal_page(base_url, input) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/popular_deals/newdeals.rb', line 26 def self.open_deal_page(base_url, input) index = input.to_i - 1 @deals = PopularDeals::NewDeals.scrap_slickdeals(base_url) @product_url = "#{@deals[index].url}" @product_url end |
.scrap_slickdeals(base_url) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/popular_deals/newdeals.rb', line 6 def self.scrap_slickdeals(base_url) doc = Nokogiri::HTML(open(base_url)) deals = [] all_deals = doc.css("div.dealRow") all_deals.collect do |one_deal| deal = self.new deal.title = one_deal.css("div.dealTitle a.track-popularDealLink").text.strip link = one_deal.css("div.dealTitle a").attribute("href").value deal.url = "https://slickdeals.net#{link}" deal. = one_deal.css("div.ratingCol div.num").text.strip deal.price = one_deal.css("div.priceCol div.price").text.strip date = one_deal.css("div.dealLinks").first.text.strip new_array = date.split deal.posted = "#{new_array[0]} #{new_array[1]}" deals << deal end deals end |