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
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
# File lib/newegg_top_games/cli.rb, line 148 def print_list(list) list.get_items #populates the list's list_array list.list = list.list[0..19] #truncates the array down to 20 items puts "" puts "NewEgg's top #{list.list.length.to_s.green} selling items for #{list.console.name.green}: " puts "-----------------------------------------------" list.list.each_with_index do |list_item, index| number = index + 1 spacer = number.to_s.length < 2 ? " " : " " puts "#{number.to_s}.#{spacer}#{list_item.name} (#{list_item.brand}) #{list_item.url == nil ? "No More info".red : ""}" end puts "" end
run()
click to toggle source
# File lib/newegg_top_games/cli.rb, line 21 def run choose_console end