Class: NeweggScraperChsbr::Cli
- Inherits:
-
Object
- Object
- NeweggScraperChsbr::Cli
- Defined in:
- lib/newegg_scraper_chsbr/cli.rb
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #call ⇒ Object
- #clear_vars ⇒ Object
- #control_bool ⇒ Object
- #cpu_make_bool ⇒ Object
- #get_init_data_for_user ⇒ Object
- #get_price_range ⇒ Object
- #if_correct_info ⇒ Object
-
#initialize ⇒ Cli
constructor
A new instance of Cli.
Constructor Details
#initialize ⇒ Cli
Returns a new instance of Cli.
3 4 5 |
# File 'lib/newegg_scraper_chsbr/cli.rb', line 3 def initialize NeweggScraperChsbr::DataGrabber.new end |
Instance Attribute Details
#user ⇒ Object (readonly)
Returns the value of attribute user.
2 3 4 |
# File 'lib/newegg_scraper_chsbr/cli.rb', line 2 def user @user end |
Instance Method Details
#call ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/newegg_scraper_chsbr/cli.rb', line 6 def call puts "Were you interested in purchasing some CPU's?" puts "Please enter y to do so." @counter = gets.strip incorrect_input = control_bool while incorrect_input puts "Were you interested in purchasing some CPU's?" puts "Please enter y to do so.\nPlease enter n or exit to quit." @counter = gets.strip incorrect_input = control_bool end while @counter == 'y' get_price_range get_init_data_for_user printed_cpus = NeweggScraperChsbr::Cpu.display_cpu(@user) if printed_cpus.size != 0 @user.choose_cpu(printed_cpus) NeweggScraperChsbr::Cpu.display_cpu_with_extras(@user) end puts "If you would like to restart the program please enter : #{@counter}.\nTo exit type n or exit." @counter = gets.strip incorrect = control_bool while incorrect puts "Were you interested in purchasing some CPU's?" puts "Please enter y to do so.\nPlease enter n or exit to quit." @counter = gets.strip incorrect = control_bool end clear_vars @user.clear_chosen self.call end puts "Thanks for using Chesbro's Scraper!" end |
#clear_vars ⇒ Object
123 124 125 126 127 |
# File 'lib/newegg_scraper_chsbr/cli.rb', line 123 def clear_vars @cpu_make = nil @min_price = nil @max_price = nil end |
#control_bool ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/newegg_scraper_chsbr/cli.rb', line 106 def control_bool if @counter == "y" false elsif @counter == "exit" || @counter == "n" false else true end end |
#cpu_make_bool ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/newegg_scraper_chsbr/cli.rb', line 115 def cpu_make_bool if @cpu_make == "x" || @cpu_make == "a" || @cpu_make == "i" false else true end end |
#get_init_data_for_user ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/newegg_scraper_chsbr/cli.rb', line 44 def get_init_data_for_user if @counter == 'y' puts "Are you searching for Intel or AMD?" puts "Please put i for Intel, or a for AMD." puts "Please put x for either." @cpu_make = gets.strip not_found = cpu_make_bool while not_found puts "Are you searching for Intel or AMD?" puts "Please put i for Intel, or a for AMD." puts "Please put x for either." @cpu_make = gets.strip not_found = cpu_make_bool end puts "\n\nYou want to search for (an) #{NeweggScraperChsbr::Cpu.cpu_maker(@cpu_make)} CPU." if @max_price.to_i != 0 && @min_price.to_i != 0 puts "You entered a maximum price of $#{@max_price}, and a minimum price of $#{@min_price}." elsif @max_price.to_i != 0 puts "You entered a maximum price of $#{@max_price}." else puts "You did not set a price to search for." end if_correct_info end end |
#get_price_range ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/newegg_scraper_chsbr/cli.rb', line 83 def get_price_range puts "Welcome. Would you like to set a budget? If no, set your maximum budget to 0" puts "Please enter the integer value of your maximum price." puts "$500.50, please enter as 501, or 500 to stay below budget." @max_price = gets.strip while @max_price.to_i < 0 || @max_price.to_i > 10000 || @max_price.include?("$") || @max_price.include?(".") || @max_price == nil puts "Welcome. Would you like to set a budget? If no, set your maximum budget to 0" puts "Please enter the integer value of your maximum price." puts "$500.50, please enter as 501, or 500 to stay below budget." @max_price = gets.strip end if @max_price.to_i != 0 puts "Please enter the minimum you would spend on a CPU." puts "Please use the same format as above." @min_price = gets.strip while @min_price.to_i <= 0 || @min_price.to_i >= @max_price.to_i || @min_price.include?("$") || @min_price.include?(".") || @min_price == nil puts "Please enter the minimum you would spend on a CPU." puts "Please use the same format as above." @min_price = gets.strip end end end |
#if_correct_info ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/newegg_scraper_chsbr/cli.rb', line 73 def if_correct_info puts "\nIf you're satisfied with your selection, the computer will print\na list of CPUs that satisfy the criteria. Enter y to continue. Enter n to choose again." @counter = gets.strip if @counter == 'y' @user = NeweggScraperChsbr::User.new(@cpu_make, @min_price, @max_price) else @counter = 'y' call end end |