steam-upcoming 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e0b73c4b1a02bbca55e3d395ce27870817e386b
4
- data.tar.gz: f16aa465b2d3db2867c9878518f91fac83fe2f05
3
+ metadata.gz: 60f01b9aab0c1d3bacfa0a33fab1b8de15e39770
4
+ data.tar.gz: b7d96181a097415fa89b3237e37a61cae653815c
5
5
  SHA512:
6
- metadata.gz: 721c3d8bc6d9163d0dcb3a2d36168eeb4bd1bdc46cf8d93cba437b9080907aa97af5d70f927192125f346760b2fe6a80c1cc6a490d091643fe2c4650bb2a102f
7
- data.tar.gz: 6db0be667baa2d2e0a3aaf3065fff1c859a8c5ac7ec6fba397803cb3414d380b71cd79da0da0497fdc9d0dd3f15c9e92253b168a839d7a5470abff161e3a590b
6
+ metadata.gz: cea802dc82d096666bc4e5aacd30e7bf2db61c4023994bf1654f19c75297063dfe8d735df8dc1ec1883715dbd25fee56f1d397cf81440a5b42a49ef3f7460748
7
+ data.tar.gz: 657b0553e3bb5170b02d7af469bd2a673df95bafd06722b68d959e3da260f412389931ef6cd90e9049e04293c729a1b2a5effbb84fdc3f3b4fe075fd5985137d
@@ -2,6 +2,7 @@ require 'open-uri'
2
2
  require 'pry'
3
3
  require 'nokogiri'
4
4
  require "colorize"
5
- require_relative "../lib/steam-upcoming/cli.rb"
5
+
6
+ require_relative "../lib/steam-upcoming/scraper.rb"
6
7
  require_relative "../lib/steam-upcoming/game.rb"
7
- require_relative "../lib/steam-upcoming/scraper.rb"
8
+ require_relative "../lib/steam-upcoming/cli.rb"
@@ -1,5 +1,4 @@
1
- require_relative "../config/environment"
2
-
3
1
  module SteamUpcoming
4
2
  end
5
3
 
4
+ require_relative "../config/environment"
@@ -3,7 +3,6 @@ class SteamUpcoming::CLI
3
3
 
4
4
  BASE_URL = "http://store.steampowered.com/search/?filter=comingsoon&sort_order=0&filter=comingsoon&page=1"
5
5
 
6
-
7
6
  def initialize
8
7
  @url = "http://store.steampowered.com/search/?filter=comingsoon&sort_order=0&filter=comingsoon&page=1"
9
8
  end
@@ -15,21 +14,21 @@ class SteamUpcoming::CLI
15
14
  start
16
15
  end
17
16
 
18
- def make_games(url) #creates the list of games from the URL
17
+ def make_games(url) #creates the list of game objects from the chosen URL
19
18
  game_array = SteamUpcoming::Scraper.scrape_index_page(url)
20
19
  SteamUpcoming::Game.create_from_collection(game_array)
21
20
  end
22
21
 
23
- def pages #generate list of pages
22
+ def pages #generate list of page URLs as an array
24
23
  pages = SteamUpcoming::Game.create_pages(SteamUpcoming::Scraper.page_count(BASE_URL))
25
24
  end
26
25
 
27
26
  def change_page #allow the users to select another page
28
27
  print "Enter a page number > "
29
28
  input = gets.chomp.strip
30
- if @url = pages[input.to_i-1]
31
- SteamUpcoming::Game.reset
32
- make_games(@url)
29
+ if @url = pages[input.to_i-1] #use the users input to select the corresponding page URL from the #pages array
30
+ SteamUpcoming::Game.reset #clear out the class variable so it can be populated with a new list of games
31
+ make_games(@url) #create the games with the new chosen URL
33
32
  list
34
33
  else
35
34
  puts "#{input}".concat(" is not a valid page number. Please enter a number between 1 and #{pages.count}.").colorize(:red)
@@ -62,15 +61,17 @@ class SteamUpcoming::CLI
62
61
  end
63
62
 
64
63
  def current_page
65
- url = @url[-2,2]
66
- array = url.split("").map {|x| x.to_i}
64
+ url = @url[-2,2] #return the last two characters of the URL string
65
+ array = url.split("").map {|x| x.to_i} #split the two characters into an array
67
66
  array[0] == 0 ? current_page = array[0] + array[1] : current_page = "#{array[0]}".concat("#{array[1]}")
67
+ #if the first element is a letter (it converts to 0), add it to the second element
68
+ #if the both elements are numbers, concatenate them and return the new string
68
69
  end
69
70
 
70
71
  def start #start the program loop
71
72
  list
72
73
  input = nil
73
- while input != "exit"
74
+ while input != "exit" #loop user input until user types 'exit'
74
75
  puts "\nLearn more about a game by typing a name or number.\n".colorize(:yellow)
75
76
  puts "Enter \'list\'' to list games.".colorize(:light_blue)
76
77
  puts "Enter \'exit\' to exit.".colorize(:light_blue)
@@ -80,17 +81,17 @@ class SteamUpcoming::CLI
80
81
  if input == "list"
81
82
  list
82
83
  elsif input.to_i == 0 #if input is a name
83
- if game = SteamUpcoming::Game.find_by_name(input)
84
+ if game = SteamUpcoming::Game.find_by_name(input) #find game and list corresponding game
84
85
  list_game(game)
85
- elsif input == "exit"
86
+ elsif input == "exit" #exit the program
86
87
  break
87
- elsif input == "page"
88
+ elsif input == "page" #commence the #change_page method
88
89
  change_page
89
90
  else
90
- puts "\'#{input}\'".concat(" is not a valid title.").colorize(:red)
91
+ puts "\'#{input}\'".concat(" is not a valid command.").colorize(:red)
91
92
  end
92
- elsif input.to_i > 0 #if a number, look up the number
93
- if game = SteamUpcoming::Game.find(input.to_i)
93
+ elsif input.to_i > 0 #if a number
94
+ if game = SteamUpcoming::Game.find(input.to_i) #find number and list corresponding game
94
95
  list_game(game)
95
96
  else
96
97
  puts "\'#{input}\'".concat(" is not a valid number. Please enter a number between 1 and #{SteamUpcoming::Game.all.count}.").colorize(:red)
@@ -99,4 +100,6 @@ class SteamUpcoming::CLI
99
100
  end
100
101
  puts "\nShutting down...\n".colorize(:red)
101
102
  end
103
+
102
104
  end
105
+
@@ -1,3 +1,6 @@
1
+ # The SteamUpcoming::Game class is responsible for taking informatino scraped from the Steam website
2
+ # and creating new Game objects with attributes.
3
+
1
4
  class SteamUpcoming::Game
2
5
  attr_accessor :name, :release_date, :platforms, :url, :about, :tags, :details
3
6
 
@@ -14,11 +17,11 @@ class SteamUpcoming::Game
14
17
  end
15
18
  end
16
19
 
17
- def add_game_attributes(game_attributes_hash) #add attributes to game
20
+ def add_game_attributes(game_attributes_hash) #add attributes to the Game object
18
21
  game_attributes_hash.each {|key, value| self.send(("#{key}="), value)}
19
22
  end
20
23
 
21
- def self.create_pages(page_count) #create the page urls
24
+ def self.create_pages(page_count) #Create the page urls
22
25
  i = 1
23
26
  pages = []
24
27
  while i <= page_count.to_i
@@ -28,10 +31,12 @@ class SteamUpcoming::Game
28
31
  pages
29
32
  end
30
33
 
34
+ private
31
35
  def self.all #show all games
32
36
  @@all
33
37
  end
34
38
 
39
+ private
35
40
  def self.reset #clear the list of games
36
41
  @@all.clear
37
42
  end
@@ -19,14 +19,14 @@ class SteamUpcoming::Scraper
19
19
  game_array
20
20
  end
21
21
 
22
- def self.gather_platforms(parent) #gather a list of platforms, then return an array of legit platforms
22
+ def self.gather_platforms(parent) #gather a list of platforms, then return an array of actual platforms
23
23
  platforms = parent.children.map do |platform|
24
24
  platform.attr('class')
25
25
  end
26
26
  platforms.select {|platform| platform != nil}
27
27
  end
28
28
 
29
- def self.convert_platforms(platform_array) #need to convert the platform array items into actual names, because the source is an image, not
29
+ def self.convert_platforms(platform_array) #convert the platform array items into actual names, because the source is an image, not text
30
30
  platforms = platform_array.map! do |platform|
31
31
  if platform.include?("win")
32
32
  platform = "Windows"
@@ -47,7 +47,7 @@ class SteamUpcoming::Scraper
47
47
  platforms.select {|platform| platform != nil}
48
48
  end
49
49
 
50
- def self.scrape_game_page(game_url)
50
+ def self.scrape_game_page(game_url) #scrape the page and create a hash of game attributes
51
51
  doc = Nokogiri::HTML(open(game_url))
52
52
  about = doc.css(".game_description_snippet")
53
53
  tags = doc.css(".glance_tags a").map {|tag| tag.text}
@@ -59,7 +59,7 @@ class SteamUpcoming::Scraper
59
59
  }
60
60
  end
61
61
 
62
- def self.page_count(index_url)
62
+ def self.page_count(index_url) #scrape the pages to get the total number of pages
63
63
  doc = Nokogiri::HTML(open(index_url))
64
64
  page_count = doc.css(".search_pagination_right").first.children[5].text.to_i
65
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steam-upcoming
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Cassara