class NewEggTopGames::CLI

Constants

CONSOLE_INFO

Public Instance Methods

choose_console() click to toggle source
# File lib/newegg_top_games/cli.rb, line 25
def choose_console
        puts ""
        puts "************************************************************".colorize(:color => :yellow).colorize(:background => :light_blue)
        puts "         _ _  _____ __ __  ___ __ _ __ _                    ".colorize(:color => :white).colorize(:background => :light_blue)
        puts "        | ' \\/ -_) V  V / / -_) _` / _` |                   ".colorize(:color => :white).colorize(:background => :light_blue)
        puts "        |_||_\\___|\\_/\\_/  \\___\\__, \\__, |  top games        ".colorize(:color => :white).colorize(:background => :light_blue)
puts "                              |___/|___/                    ".colorize(:color => :white).colorize(:background => :light_blue)
        puts "************************************************************".colorize(:color => :yellow).colorize(:background => :light_blue)
        input = nil
        puts ""
        
        number = 1
        CONSOLE_INFO.each do |key, value|
                spacer = number.to_s.length < 2 ? "  " : " "
                puts "#{number.to_s.yellow}.#{spacer}#{CONSOLE_INFO[key][:name]}"
                number +=1
        end
        puts ""
        puts "************************************************************"
        puts ""
        input = nil
        
        while input != "EXIT"
                print "Choose a console or type #{'exit'.red} to exit (1-#{CONSOLE_INFO.keys.length}): "
                
                input = gets.chomp.upcase

                case input
                when "1"
                        console_menu(CONSOLE_INFO[:playstation_4])
                when "2"
                        console_menu(CONSOLE_INFO[:playstation_3])
                when "3"
                        console_menu(CONSOLE_INFO[:playstation_2])
                when "4"
                        console_menu(CONSOLE_INFO[:xbox_one])
                when "5"
                        console_menu(CONSOLE_INFO[:xbox_360])
                when "6"
                        console_menu(CONSOLE_INFO[:wii])
                when "7" 
                        console_menu(CONSOLE_INFO[:wii_u])
                when "8" 
                        console_menu(CONSOLE_INFO[:nintendo_ds])
                when "9" 
                        console_menu(CONSOLE_INFO[:nintendo_switch])
                when "10"
                        console_menu(CONSOLE_INFO[:vr_games])
                when "11"
                        console_menu(CONSOLE_INFO[:pc_games])
                when "12"
                        console_menu(CONSOLE_INFO[:featured_items])
                when "EXIT"
                        exit_program
                else
                        puts "Invalid Entry, try again...".red
                end
        end
end
console_menu(console_info) click to toggle source
# File lib/newegg_top_games/cli.rb, line 85
def console_menu(console_info)
        list = NewEggTopGames::ConsoleTopTwentyList.new(NewEggTopGames::Console.new(console_info))
        print_list(list)
        input = nil
        
        while input != "EXIT"
                print "Which Item would you like to know more about? Type 'list' to re-list items, 'consoles' to return to consoles, or #{"'exit'".red} to exit (1-#{list.list.length}): "
                input = gets.chomp.upcase
                if input.to_i > 0 && input.to_i <= list.list.length
                        product_page = NewEggTopGames::Scraper.product_page(list.list[input.to_i - 1])
                        present_product_page(product_page, console_info)
                end
                
                case input
                when "CONSOLES"
                        choose_console
                when "LIST"
                        console_menu(console_info)
                when "EXIT"
                        exit_program
                else
                        puts "Invalid Entry, try again...".red
                end
        end
end
exit_program() click to toggle source
# File lib/newegg_top_games/cli.rb, line 163
def exit_program
        puts ""
        puts "Thank you, see you next time!"
        puts ""
        exit
end
present_product_page(product_page, console_info) click to toggle source
# File lib/newegg_top_games/cli.rb, line 111
def present_product_page(product_page, console_info)
        price = product_page.price.split('.')[1].length == 1 ? product_page.price + "0" : product_page.price
        puts ""
        puts "********************************************************"
        puts "#{product_page.title}"
        puts "********************************************************"
        puts ""
        puts "Price:   #{"$".green}#{price.green}"
        puts "Console: #{product_page.console.name.green}"
        puts ""
        puts "Description:".light_blue
        puts "------------------"
        puts ""
        product_page.info_array.each do |item|
                puts item.text.strip
                puts ""
        end
        puts "------------------"
        puts ""
        input = nil
        
        while input != "EXIT"
                print "Type 'list' to go back to the #{console_info[:name].green} list, 'consoles' to go back to the consoles, or #{"'exit'".red} to exit: "
                input = gets.strip.upcase
                case input
                when "LIST"
                        console_menu(console_info)
                when "CONSOLES"
                        choose_console
                when "EXIT"
                        exit_program
                else
                        puts "Invalid entry, try again...".red
                end
        end
end
print_list(list) click to toggle source
run() click to toggle source
# File lib/newegg_top_games/cli.rb, line 21
def run
        choose_console                
end