latest_games 0.0.6 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 125c2b424928a3ab4a53b3400a01df724c13ece6
4
- data.tar.gz: a937281c13adf6821212734c4456e8f803962734
3
+ metadata.gz: 62cf1f30ae04613f407a2b817fb93d7159e4d642
4
+ data.tar.gz: 5332cd36a0b3692cfc5a15b58f68f16d5bb42f87
5
5
  SHA512:
6
- metadata.gz: 5725e5e77872b6f4b70629e2169ba4442399a2ff05b489e2304892d0dde24ef06b428b73be7b0570c693776e5b4cbcb67c346caa871e9febafb937845097bf49
7
- data.tar.gz: 2f64b6741c76b1457b670d821a39431c1997491e4cf8f13791d0a69b2abdc3d93c028e837ef5eb33135d3f8ed4a4f27684901b3d4b0c3fbe09fbb8a3b04ad804
6
+ metadata.gz: 3b35bbcd6770a6ece3a9463d67bd231c4e53341d8e80cd3497b08c8b450b1bc59710a3ed13d6abd06eb562cf7223c537172cc88e8b72dd0c70210a5ca933c04e
7
+ data.tar.gz: ddc88e268856d15e19d855c38b4bcd92fcf9d3231a332eac050427129c06f637afc711ca42382c9aaa8a9c1380a7e41d636a8017593727661715ae5030a0c023
data/bin/latest_games CHANGED
File without changes
@@ -1,6 +1,7 @@
1
1
  require 'pry'
2
2
  require 'open-uri'
3
3
  require 'nokogiri'
4
+ require 'colorize'
4
5
 
5
6
  require_relative "../lib/latest_games/cli"
6
7
  require_relative "../lib/latest_games/ps4game"
@@ -1,42 +1,178 @@
1
1
  class LatestGames::CLI
2
2
 
3
3
  def call
4
+ puts ""
5
+ puts "******** Latest Video Games and Reviews ********"
6
+ puts ""
4
7
  self.start
5
8
  end
6
9
 
7
10
  def list_platforms
8
- puts ""
9
- puts "******** Latest Video Games and Reviews ********"
10
- puts ""
11
- puts "******===> Select a gaming platform: <===*******"
12
- puts ""
13
- puts "1) PS4"
14
- puts "2) Xbox One"
15
- puts "3) Switch"
16
- puts "4) PC"
17
- puts "5) iOS"
11
+ puts "------> Select a gaming platform: <------"
12
+ puts "1. PS4"
13
+ puts "2. Xbox One"
14
+ puts "3. Switch"
15
+ puts "4. PC"
16
+ puts "5. iOS"
17
+ puts "-----------------------------------------"
18
+ puts "(To quit, enter 'exit' at any time..)".red
18
19
  end
19
20
 
20
21
  def start
21
22
  self.list_platforms
22
23
  input = nil
23
- while input != "exit"
24
+ until input == "exit"
25
+ input = nil
24
26
  puts ""
25
- puts "Enter the corresponding number to select a platform:"
27
+ puts "Select a platform:"
26
28
  input = gets.strip
27
- if input.to_i == 0 && input != "exit"
29
+ if input.to_i == 1 || input.downcase == "ps4"
30
+ platform = LatestGames::PS4Game.new
31
+ list_games(platform)
32
+ elsif input.to_i == 2 || input.downcase == "xbox one"
33
+ platform = LatestGames::XboneGame.new
34
+ list_games(platform)
35
+ elsif input.to_i == 3 || input.downcase == "switch"
36
+ platform = LatestGames::SwitchGame.new
37
+ list_games(platform)
38
+ elsif input.to_i == 4 || input.downcase == "pc"
39
+ platform = LatestGames::PCGame.new
40
+ list_games(platform)
41
+ elsif input.to_i == 5 || input.downcase == "ios"
42
+ platform = LatestGames::IOSGame.new
43
+ list_games(platform)
44
+ elsif input.to_i == 0 && input != "exit"
28
45
  puts ""
29
- puts "Please enter the number, not the platform name!"
30
- puts "Restarting..."
46
+ puts "That didn't quite work.. check your spelling and try again!"
47
+ puts "Reprinting list..."
31
48
  sleep(2)
32
49
  start
33
- elsif input.to_i > 0
34
- puts "LIST OF [PLATFORM] GAMES HERE"
35
50
  end
36
51
  end
37
52
  puts ""
53
+ puts "------------"
38
54
  puts "Hope you found something you like!"
39
55
  puts "Have a great day! :D"
40
56
  end
41
57
 
58
+ def list_games(platform)
59
+ input = nil
60
+ until input == "exit"
61
+ puts ""
62
+ if platform.is_a? LatestGames::PS4Game
63
+ puts "*************** Latest PS4 Games ***************"
64
+ puts ""
65
+ wait_cursor(1)
66
+ LatestGames::PS4Game.all[0..9].each.with_index(1) {|game, i|
67
+ puts "#{i}. #{game.name}"
68
+ }
69
+ puts ""
70
+ puts "Select a game to get more info:"
71
+ input = gets.strip
72
+ game = LatestGames::PS4Game.find(input.to_i)
73
+ select_game(game, "PS4")
74
+
75
+ elsif platform.is_a? LatestGames::IOSGame
76
+ puts "*************** Latest iOS Games ***************"
77
+ puts ""
78
+ wait_cursor(1)
79
+ LatestGames::IOSGame.all[0..9].each.with_index(1) {|game, i|
80
+ puts "#{i}. #{game.name}"
81
+ }
82
+ puts ""
83
+ puts "Select a game to get more info:"
84
+ input = gets.strip
85
+ game = LatestGames::IOSGame.find(input.to_i)
86
+ select_game(game, "iOS")
87
+
88
+ elsif platform.is_a? LatestGames::XboneGame
89
+ puts "************* Latest Xbox One Games ************"
90
+ puts ""
91
+ wait_cursor(1)
92
+ LatestGames::XboneGame.all[0..9].each.with_index(1) {|game, i|
93
+ puts "#{i}. #{game.name}"
94
+ }
95
+ puts ""
96
+ puts "Select a game to get more info:"
97
+ input = gets.strip
98
+ game = LatestGames::XboneGame.find(input.to_i)
99
+ select_game(game, "Xbox One")
100
+
101
+ elsif platform.is_a? LatestGames::PCGame
102
+ puts "*************** Latest PC Games ****************"
103
+ puts ""
104
+ wait_cursor(1)
105
+ LatestGames::PCGame.all[0..9].each.with_index(1) {|game, i|
106
+ puts "#{i}. #{game.name}"
107
+ }
108
+ puts ""
109
+ puts "Select a game to get more info:"
110
+ input = gets.strip
111
+ game = LatestGames::PCGame.find(input.to_i)
112
+ select_game(game, "PC")
113
+
114
+ elsif platform.is_a? LatestGames::SwitchGame
115
+ puts "************* Latest Switch Games **************"
116
+ puts ""
117
+ wait_cursor(1)
118
+ LatestGames::SwitchGame.all[0..9].each.with_index(1) {|game, i|
119
+ puts "#{i}. #{game.name}"
120
+ }
121
+ puts ""
122
+ puts "Select a game to get more info:"
123
+ input = gets.strip
124
+ game = LatestGames::SwitchGame.find(input.to_i)
125
+ select_game(game, "Switch")
126
+
127
+ end
128
+ end
129
+ end
130
+
131
+ def select_game(game, platform)
132
+ puts ""
133
+ puts "------- #{game.name} - #{platform} -------"
134
+ puts ""
135
+ puts "Publisher: #{game.publisher}"
136
+ puts "Release Date: #{game.release_date}"
137
+ if game.also_on == ""
138
+ puts "Only on #{platform}"
139
+ else
140
+ puts "Also On: #{game.also_on}"
141
+ end
142
+ puts ""
143
+ if game.metascore.to_i == 0
144
+ puts "Metascore: TBD"
145
+ elsif game.metascore.to_i >= 75
146
+ puts "Metascore: #{game.metascore.green}"
147
+ elsif game.metascore.to_i < 75 && game.metascore.to_i >= 50
148
+ puts "Metascore: #{game.metascore.yellow}"
149
+ elsif game.metascore.to_i < 50
150
+ puts "Metascore: #{game.metascore.red}"
151
+ end
152
+ puts ""
153
+ if game.summary == ""
154
+ puts "No Summary Provided"
155
+ else
156
+ puts "Summary: #{game.summary[0...500]}.."
157
+ end
158
+ puts ""
159
+ puts "--------------------"
160
+ puts ""
161
+ puts "Would you like to check out another #{platform} game? (y/n)"
162
+ input = gets.strip
163
+ if input.downcase == "n" || input.downcase == "no"
164
+ self.start
165
+ end
166
+ end
167
+
168
+ def wait_cursor(seconds,fps=10)
169
+ chars = %w[| / - \\]
170
+ delay = 1.0/fps
171
+ (seconds*fps).round.times{ |i|
172
+ print "Loading.. " + chars[i % chars.length]
173
+ sleep delay
174
+ print "\b\b\b\b\b\b\b\b\b\b\b"
175
+ }
176
+ end
177
+
42
178
  end
@@ -1,5 +1,5 @@
1
1
  class LatestGames::IOSGame
2
- attr_accessor :name, :url, :release_date, :metascore, :publisher, :also_on
2
+ attr_accessor :name, :url, :summary, :release_date, :metascore, :publisher, :also_on
3
3
 
4
4
  def initialize(name = nil, url = nil)
5
5
  @name = name
@@ -10,4 +10,46 @@ class LatestGames::IOSGame
10
10
  @@all ||= scrape_ios_games
11
11
  end
12
12
 
13
+ def self.find(i)
14
+ self.all[i-1]
15
+ end
16
+
17
+ def self.find_by_name(name)
18
+ self.all.detect do |game|
19
+ game.name.downcase.strip == name.downcase.strip ||
20
+ game.name.split("(").first.strip.downcase == name.downcase.strip
21
+ end
22
+ end
23
+
24
+ def summary
25
+ @summary ||= doc.xpath("//*[@id='main']/div/div[3]/div/div[2]/div[2]/div[1]/ul/li/span[2]/span").text.strip
26
+ end
27
+
28
+ def release_date
29
+ @release_date ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[2]/span[2]").text.strip
30
+ end
31
+
32
+ def metascore
33
+ @metascore ||= doc.xpath("//*[@id='main']/div/div[3]/div/div[2]/div[1]/div[1]/div/div/a/div/span").text.strip
34
+ end
35
+
36
+ def publisher
37
+ @publisher ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[1]/span[2]/a/span").text.strip
38
+ end
39
+
40
+ def also_on
41
+ @also_on ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[3]/span[2]").text.strip
42
+ end
43
+
44
+ private
45
+ def self.scrape_ios_games
46
+ doc = Nokogiri::HTML(open('http://www.metacritic.com/browse/games/release-date/new-releases/ios', 'User-Agent'=>'chrome'))
47
+ names = doc.search("div[class='basic_stat product_title'] a")
48
+ names.collect{|title| new(title.text.strip, "http://www.metacritic.com#{title.attr("href")}")}
49
+ end
50
+
51
+ def doc
52
+ @doc ||= Nokogiri::HTML(open(self.url, 'User-Agent'=>'chrome'))
53
+ end
54
+
13
55
  end
@@ -1,5 +1,5 @@
1
1
  class LatestGames::PCGame
2
- attr_accessor :name, :url, :release_date, :metascore, :publisher, :also_on
2
+ attr_accessor :name, :url, :summary, :release_date, :metascore, :publisher, :also_on
3
3
 
4
4
  def initialize(name = nil, url = nil)
5
5
  @name = name
@@ -10,4 +10,46 @@ class LatestGames::PCGame
10
10
  @@all ||= scrape_pc_games
11
11
  end
12
12
 
13
+ def self.find(i)
14
+ self.all[i-1]
15
+ end
16
+
17
+ def self.find_by_name(name)
18
+ self.all.detect do |game|
19
+ game.name.downcase.strip == name.downcase.strip ||
20
+ game.name.split("(").first.strip.downcase == name.downcase.strip
21
+ end
22
+ end
23
+
24
+ def summary
25
+ @summary ||= doc.xpath("//*[@id='main']/div/div[3]/div/div[2]/div[2]/div[1]/ul/li/span[2]/span").text
26
+ end
27
+
28
+ def release_date
29
+ @release_date ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[2]/span[2]").text.strip
30
+ end
31
+
32
+ def metascore
33
+ @metascore ||= doc.xpath("//*[@id='main']/div/div[3]/div/div[2]/div[1]/div[1]/div/div/a/div/span").text.strip
34
+ end
35
+
36
+ def publisher
37
+ @publisher ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[1]/span[2]/a/span").text.strip
38
+ end
39
+
40
+ def also_on
41
+ @also_on ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[3]/span[2]").text.strip
42
+ end
43
+
44
+ private
45
+ def self.scrape_pc_games
46
+ doc = Nokogiri::HTML(open('http://www.metacritic.com/browse/games/release-date/new-releases/pc', 'User-Agent'=>'chrome'))
47
+ names = doc.search("div[class='basic_stat product_title'] a")
48
+ names.collect{|title| new(title.text.strip, "http://www.metacritic.com#{title.attr("href")}")}
49
+ end
50
+
51
+ def doc
52
+ @doc ||= Nokogiri::HTML(open(self.url, 'User-Agent'=>'chrome'))
53
+ end
54
+
13
55
  end
@@ -1,5 +1,5 @@
1
1
  class LatestGames::PS4Game
2
- attr_accessor :name, :url, :release_date, :metascore, :publisher, :also_on
2
+ attr_accessor :name, :url, :summary, :release_date, :metascore, :publisher, :also_on
3
3
 
4
4
  def initialize(name = nil, url = nil)
5
5
  @name = name
@@ -10,4 +10,46 @@ class LatestGames::PS4Game
10
10
  @@all ||= scrape_ps4_games
11
11
  end
12
12
 
13
+ def self.find(i)
14
+ self.all[i-1]
15
+ end
16
+
17
+ def self.find_by_name(name)
18
+ self.all.detect do |game|
19
+ game.name.downcase.strip == name.downcase.strip ||
20
+ game.name.split("(").first.strip.downcase == name.downcase.strip
21
+ end
22
+ end
23
+
24
+ def summary
25
+ @summary ||= doc.xpath("//*[@id='main']/div/div[3]/div/div[2]/div[2]/div[1]/ul/li/span[2]/span").text.strip
26
+ end
27
+
28
+ def release_date
29
+ @release_date ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[2]/span[2]").text.strip
30
+ end
31
+
32
+ def metascore
33
+ @metascore ||= doc.xpath("//*[@id='main']/div/div[3]/div/div[2]/div[1]/div[1]/div/div/a/div/span").text.strip
34
+ end
35
+
36
+ def publisher
37
+ @publisher ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[1]/span[2]/a/span").text.strip.gsub('/n', ' ')
38
+ end
39
+
40
+ def also_on
41
+ @also_on ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[3]/span[2]").text.strip.gsub('/n', ' ')
42
+ end
43
+
44
+ private
45
+ def self.scrape_ps4_games
46
+ doc = Nokogiri::HTML(open('http://www.metacritic.com/browse/games/release-date/new-releases/ps4', 'User-Agent'=>'chrome'))
47
+ names = doc.search("div[class='basic_stat product_title'] a")
48
+ names.collect{|title| new(title.text.strip, "http://www.metacritic.com#{title.attr("href")}")}
49
+ end
50
+
51
+ def doc
52
+ @doc ||= Nokogiri::HTML(open(self.url, 'User-Agent'=>'chrome'))
53
+ end
54
+
13
55
  end
@@ -1,5 +1,5 @@
1
1
  class LatestGames::SwitchGame
2
- attr_accessor :name, :url, :release_date, :metascore, :publisher, :also_on
2
+ attr_accessor :name, :url, :summary, :release_date, :metascore, :publisher, :also_on
3
3
 
4
4
  def initialize(name = nil, url = nil)
5
5
  @name = name
@@ -10,4 +10,46 @@ class LatestGames::SwitchGame
10
10
  @@all ||= scrape_switch_games
11
11
  end
12
12
 
13
+ def self.find(i)
14
+ self.all[i-1]
15
+ end
16
+
17
+ def self.find_by_name(name)
18
+ self.all.detect do |game|
19
+ game.name.downcase.strip == name.downcase.strip ||
20
+ game.name.split("(").first.strip.downcase == name.downcase.strip
21
+ end
22
+ end
23
+
24
+ def summary
25
+ @summary ||= doc.xpath("//*[@id='main']/div/div[3]/div/div[2]/div[2]/div[1]/ul/li/span[2]/span").text.strip
26
+ end
27
+
28
+ def release_date
29
+ @release_date ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[2]/span[2]").text.strip
30
+ end
31
+
32
+ def metascore
33
+ @metascore ||= doc.xpath("//*[@id='main']/div/div[3]/div/div[2]/div[1]/div[1]/div/div/a/div/span").text.strip
34
+ end
35
+
36
+ def publisher
37
+ @publisher ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[1]/span[2]/a/span").text.strip
38
+ end
39
+
40
+ def also_on
41
+ @also_on ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[3]/span[2]").text.strip
42
+ end
43
+
44
+ private
45
+ def self.scrape_switch_games
46
+ doc = Nokogiri::HTML(open('http://www.metacritic.com/browse/games/release-date/new-releases/switch', 'User-Agent'=>'chrome'))
47
+ names = doc.search("div[class='basic_stat product_title'] a")
48
+ names.collect{|title| new(title.text.strip, "http://www.metacritic.com#{title.attr("href")}")}
49
+ end
50
+
51
+ def doc
52
+ @doc ||= Nokogiri::HTML(open(self.url, 'User-Agent'=>'chrome'))
53
+ end
54
+
13
55
  end
@@ -1,5 +1,5 @@
1
1
  class LatestGames::XboneGame
2
- attr_accessor :name, :url, :release_date, :metascore, :publisher, :also_on
2
+ attr_accessor :name, :url, :summary, :release_date, :metascore, :publisher, :also_on
3
3
 
4
4
  def initialize(name = nil, url = nil)
5
5
  @name = name
@@ -10,4 +10,46 @@ class LatestGames::XboneGame
10
10
  @@all ||= scrape_xbone_games
11
11
  end
12
12
 
13
+ def self.find(i)
14
+ self.all[i-1]
15
+ end
16
+
17
+ def self.find_by_name(name)
18
+ self.all.detect do |game|
19
+ game.name.downcase.strip == name.downcase.strip ||
20
+ game.name.split("(").first.strip.downcase == name.downcase.strip
21
+ end
22
+ end
23
+
24
+ def summary
25
+ @summary ||= doc.xpath("//*[@id='main']/div/div[3]/div/div[2]/div[2]/div[1]/ul/li/span[2]/span").text.strip
26
+ end
27
+
28
+ def release_date
29
+ @release_date ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[2]/span[2]").text.strip
30
+ end
31
+
32
+ def metascore
33
+ @metascore ||= doc.xpath("//*[@id='main']/div/div[3]/div/div[2]/div[1]/div[1]/div/div/a/div/span").text.strip
34
+ end
35
+
36
+ def publisher
37
+ @publisher ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[1]/span[2]/a/span").text.strip
38
+ end
39
+
40
+ def also_on
41
+ @also_on ||= doc.xpath("//*[@id='main']/div/div[1]/div[2]/ul/li[3]/span[2]").text.strip
42
+ end
43
+
44
+ private
45
+ def self.scrape_xbone_games
46
+ doc = Nokogiri::HTML(open('http://www.metacritic.com/browse/games/release-date/new-releases/xboxone', 'User-Agent'=>'chrome'))
47
+ names = doc.search("div[class='basic_stat product_title'] a")
48
+ names.collect{|title| new(title.text.strip, "http://www.metacritic.com#{title.attr("href")}")}
49
+ end
50
+
51
+ def doc
52
+ @doc ||= Nokogiri::HTML(open(self.url, 'User-Agent'=>'chrome'))
53
+ end
54
+
13
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: latest_games
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Lucas Kisabeth'"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-14 00:00:00.000000000 Z
11
+ date: 2017-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler