Class: MetacriticGames::CLI
- Inherits:
-
Object
- Object
- MetacriticGames::CLI
- Defined in:
- lib/cli.rb
Overview
CLI controller
Instance Attribute Summary collapse
-
#cli ⇒ Object
Returns the value of attribute cli.
-
#genre ⇒ Object
Returns the value of attribute genre.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#build_game_array ⇒ Object
scrapes the games listed on the new release page.
-
#build_platform_array ⇒ Object
scrapes and returns the platforms listed on the new release page.
-
#call ⇒ Object
call gets everything running.
-
#game_details(game, platform) ⇒ Object
gives greater detail on a particular game and a link to access more.
-
#game_url(game, platform) ⇒ Object
since games can have multiple platforms, logic to select the correct link for the specific platform.
- #goodbye ⇒ Object
-
#list_games(platform) ⇒ Object
lists games based on the platform passed in and creates the menu option for further game details.
- #list_platforms ⇒ Object
- #starship_troopers ⇒ Object
Instance Attribute Details
#cli ⇒ Object
Returns the value of attribute cli.
6 7 8 |
# File 'lib/cli.rb', line 6 def cli @cli end |
#genre ⇒ Object
Returns the value of attribute genre.
6 7 8 |
# File 'lib/cli.rb', line 6 def genre @genre end |
#platform ⇒ Object
Returns the value of attribute platform.
6 7 8 |
# File 'lib/cli.rb', line 6 def platform @platform end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/cli.rb', line 6 def url @url end |
Class Method Details
.progressbar ⇒ Object
8 9 10 |
# File 'lib/cli.rb', line 8 def self. @@progressbar end |
Instance Method Details
#build_game_array ⇒ Object
scrapes the games listed on the new release page
30 31 32 33 34 |
# File 'lib/cli.rb', line 30 def build_game_array game_array = MetacriticGames::Scraper.scrape_new_releases game_array.reject! {|game| game == nil} game_array end |
#build_platform_array ⇒ Object
scrapes and returns the platforms listed on the new release page
25 26 27 |
# File 'lib/cli.rb', line 25 def build_platform_array MetacriticGames::Scraper.scrape_platform(self.url) end |
#call ⇒ Object
call gets everything running. sets the url for scraping main page, initializes highline for menus and progressbar for loading animation, creates platforms and games, then calls the first menu list
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cli.rb', line 13 def call self.cli = HighLine.new self.url = "http://www.metacritic.com/browse/games/release-date/new-releases/all/date" @@progressbar = ProgressBar.create(:starting_at => 20, :total => nil) MetacriticGames::Platform.create_platforms(build_platform_array) MetacriticGames::Game.create_games(build_game_array) @platform = MetacriticGames::Platform.all @genre = MetacriticGames::Genre.all list_platforms end |
#game_details(game, platform) ⇒ Object
gives greater detail on a particular game and a link to access more
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cli.rb', line 68 def game_details(game, platform) cli.say "#{game.name} has a metacritic score of #{game.[platform.name.to_sym]} and a current user score of: #{game.user_score[platform.name.to_sym]}." cli.say "It is classified to the following genres:" game.genre.each {|genre| cli.say "#{genre.name}"} sleep 1 starship_troopers game_url(game, platform) self.cli.choose do || .index = :number .index_suffix = ")" .prompt = "Which menu would you like to return to?" .choice :"Return to games list" do list_games(platform) end .choice :"Return to platform list" do list_platforms end .choice :Exit do goodbye end end end |
#game_url(game, platform) ⇒ Object
since games can have multiple platforms, logic to select the correct link for the specific platform
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/cli.rb', line 103 def game_url(game, platform) if platform.name == "Xbox One" puts "#{game.url[:XONE]}".colorize(:blue) elsif platform.name == "Wii U" puts "#{game.url[:WIIU]}".colorize(:blue) elsif platform.name == "PS Vita" puts "#{game.url[:VITA]}".colorize(:blue) else puts "#{game.url[platform.name.to_sym]}".colorize(:blue) end end |
#goodbye ⇒ Object
85 86 87 88 |
# File 'lib/cli.rb', line 85 def goodbye puts "See you next time!" exit end |
#list_games(platform) ⇒ Object
lists games based on the platform passed in and creates the menu option for further game details
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cli.rb', line 53 def list_games(platform) cli.say "Metacritic's newest releases for #{platform.name}:" self.cli.choose do || .index = :number .index_suffix = ")" .prompt = "Please choose the game you want more information on:" platform.games.each do |game| .choice :"#{game.name}" do game_details(game, platform) end end .choice :"Return to platform list" do list_platforms end .choice :Exit do goodbye end end end |
#list_platforms ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cli.rb', line 37 def list_platforms puts "\nPlatforms".bold.underline self.cli.choose do || .index = :number .index_suffix = ")" .prompt = "Please choose the platform you want new release info for:" self.platform.each do |platform| .choice :"#{platform.name}" do list_games(platform) end end .choice :"List Platforms" do list_platforms end .choice :Exit do goodbye end end end |
#starship_troopers ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cli.rb', line 90 def starship_troopers msg = "Would you like to know more?".bold 5.times do print "\r#{msg}" sleep 0.3 print "\r#{ ' ' * msg.size}" sleep 0.3 end puts "\nClick the link for more details".bold end |