class SteamDeals::Deal

Attributes

app_desc[RW]
app_type[RW]
details_url[RW]
developer[RW]
discount[RW]
highest_discount[RW]
name[RW]
price[RW]
publisher[RW]
supported_os[RW]

Public Class Methods

app_at(num) click to toggle source
# File lib/steam_deals/deal.rb, line 44
def self.app_at(num)
  @@apps[num-1]
end
apps() click to toggle source
# File lib/steam_deals/deal.rb, line 32
def self.apps
  @@apps
end
new(name = "", url = "", discount = "", price = "", highest_discount = "") click to toggle source
# File lib/steam_deals/deal.rb, line 8
def initialize(name = "", url = "", discount = "", price = "", highest_discount = "")
  @name = name
  @details_url = url
  @discount = discount
  @highest_discount = highest_discount
  @price = price
  @developer = "N/A"
  @publisher = "N/A"
  @supported_os = "N/A"
  @app_desc = "N/A"
end
scrape_initial_details(app_list) click to toggle source
# File lib/steam_deals/deal.rb, line 55
def self.scrape_initial_details(app_list)
  app_list.each do |app|
    app_name = app.css("a.b")[0].text
    app_url ="https://steamdb.info/#{app.css("a.b")[0]["href"]}"
    discount = app.css("td")[3].text
    highest_discount = app.css("td")[2].css(".highest-discount").text
    price = "#{app.css("td")[4].text}"
    game = SteamDeals::Deal.new(app_name, app_url, discount,  price, highest_discount)
    @@apps << game
  end
end
scrape_section_apps(section) click to toggle source
# File lib/steam_deals/deal.rb, line 48
def self.scrape_section_apps(section)
  @@apps.clear
  app_list = section[:css].css(".table-sales .appimg")
  scrape_initial_details(app_list)
end
scrape_sections() click to toggle source
# File lib/steam_deals/deal.rb, line 20
def self.scrape_sections
  @@sections.clear
  doc = Nokogiri::HTML(open("https://steamdb.info/sales/"))
  section_css = doc.css(".sales-section")
  while section_css.length > 0
    target_section = section_css.shift
    section_name = target_section.css(".pre-table-title a").text
    @@sections << {name: section_name, css: target_section}
  end
  self.sections
end
section_at(num) click to toggle source
# File lib/steam_deals/deal.rb, line 40
def self.section_at(num)
  @@sections[num-1]
end
sections() click to toggle source
# File lib/steam_deals/deal.rb, line 36
def self.sections
  @@sections
end

Public Instance Methods

scrape_add_details() click to toggle source
# File lib/steam_deals/deal.rb, line 67
def scrape_add_details
  doc = Nokogiri::HTML(open(@details_url))
  @app_desc = doc.css(".span4 p.header-description").text
  app_details = doc.css(".table-dark tr")
  if app_details[0].css("td")[0].text == "App ID"
    @app_type = app_details[1].css("td")[1].text 
    @developer = app_details[3].css("td")[1].text 
    @publisher = app_details[4].css("td")[1].text
    @supported_os = app_details.css(".icon").collect{|element| element["aria-label"]}.join(", ")
  end
end