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(input, product_url) ⇒ Object
- .new_deals ⇒ Object
- .open_deal_page(input) ⇒ Object
- .scrap_deals ⇒ Object
- .scrap_slickdeals ⇒ 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 @deal_rating 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(input, product_url) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/popular_deals/newdeals.rb', line 45 def self.deal_page(input, product_url) self.open_deal_page(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 #@purchase_link = "" if doc.at_css("a#largeBuyNow").nil? deal[:purchase] = @product_url else deal[:purchase] = doc.at_css("a#largeBuyNow").attr("href") end # @purchase_link= doc.at_css("a#largeBuyNow").attr("href") # if @purchase_link.nil? # deal[:purchase] = @product_url # else # deal[:purchase] = @purchase_link # end deal end |
.new_deals ⇒ Object
6 7 8 |
# File 'lib/popular_deals/newdeals.rb', line 6 def self.new_deals self.scrap_deals end |
.open_deal_page(input) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/popular_deals/newdeals.rb', line 35 def self.open_deal_page(input) index = input.to_i - 1 @deals = PopularDeals::NewDeals.new_deals @deals.each do |info| d = info[index] @product_url = "#{d.url}" end @product_url end |
.scrap_deals ⇒ Object
10 11 12 13 14 |
# File 'lib/popular_deals/newdeals.rb', line 10 def self.scrap_deals deals = [] deals << self.scrap_slickdeals deals end |
.scrap_slickdeals ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/popular_deals/newdeals.rb', line 16 def self.scrap_slickdeals doc = Nokogiri::HTML(open("https://slickdeals.net/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]}" deal end end |