class Scraper

require 'pry'

Public Class Methods

all_games() click to toggle source
# File lib/scraper.rb, line 49
def self.all_games
  games = {}
  p1 = 0
  p2 = 1
  get_page.css(".entry-title a").each do |entry|
    title = entry.text
    #binding.pry
    games[title.to_sym] = {
    :description => descriptions[p1] + " " + descriptions[p2]
    }
    p1 += 2
    p2 += 2
  end
  games
end
cpu_games() click to toggle source
# File lib/scraper.rb, line 65
def self.cpu_games
  games = {}
  p1 = 0
  p2 = 1
  cpu_get_page.css(".entry-title a").each do |entry|
    title = entry.text
    #binding.pry
    games[title.to_sym] = {
      :description => descriptions[p1] + " " + descriptions[p2]
    }
    p1 += 2
    p2 += 2
  end
  games
end
cpu_get_page() click to toggle source
# File lib/scraper.rb, line 17
def self.cpu_get_page
    html = open("https://www.alphabetagamer.com/page/5/")
  doc = Nokogiri::HTML(html)
  doc
  #Titles ====== get_page.css(".entry-title a")
  #Descriptions ====== get_page.css(".entry-content p")
end
cpu_make_games() click to toggle source
# File lib/scraper.rb, line 93
def self.cpu_make_games
  cpu_games.clear
  cpu_games.each do |game|
    a = Games.new(game[0], game[1])
    @cpugames << a
    Games.all.delete(a)
  end
end
cpugames() click to toggle source
# File lib/scraper.rb, line 89
def self.cpugames
  @cpugames
end
descriptions() click to toggle source
# File lib/scraper.rb, line 25
def self.descriptions
  arr = []
  desc = get_page.css(".entry-content p")

  desc.each do |item|
    if item.text != ""
      arr << item.text
    end
  end
  arr
end
get_page() click to toggle source
# File lib/scraper.rb, line 9
def self.get_page
  html = open("https://www.alphabetagamer.com")
  doc = Nokogiri::HTML(html)
  doc
  #Titles ====== get_page.css(".entry-title a")
  #Descriptions ====== get_page.css(".entry-content p")
end
list_games() click to toggle source
# File lib/scraper.rb, line 38
def self.list_games
  index = 1
  all_games.each do |title, description|
    puts "#{index}. #{(title)}"
    puts "#{description.values.first}"
    puts ""
    puts ""
    index += 1
  end
end
make_games() click to toggle source
# File lib/scraper.rb, line 81
def self.make_games
  all_games.each do |game|
    Games.new(game[0], game[1])
  end
  all_games.clear
end