class Headphones::CLI
Public Instance Methods
again()
click to toggle source
# File lib/headphones-buyers-guide-cli-gem/cli.rb, line 84 def again puts "Do you want to search again? y/n" input = nil while input != "n" input = gets.strip if input == "y" call else puts "Do you want to search again? y/n" end end goodby end
call()
click to toggle source
# File lib/headphones-buyers-guide-cli-gem/cli.rb, line 4 def call greeting start end
generate_list(array)
click to toggle source
# File lib/headphones-buyers-guide-cli-gem/cli.rb, line 72 def generate_list(array) array.each.with_index do |h, i| puts "#{i + 1}. #{array[i][:name].colorize(:green)} #{array[i][:price]} \n #{array[i][:description]}" puts "#{array[i][:rating]}" puts " " end end
goodby()
click to toggle source
# File lib/headphones-buyers-guide-cli-gem/cli.rb, line 98 def goodby puts "Goodby and good luck finding the perfect hedphones!" exit end
greeting()
click to toggle source
# File lib/headphones-buyers-guide-cli-gem/cli.rb, line 9 def greeting puts(<<~EOT) Welcome to the Headphone Buyer's Guide --------------------------- To begin choose a headphone type, to quit type exit" 1. In-ear 2. Over-ear 3. On-ear EOT end
more_info(input, array)
click to toggle source
# File lib/headphones-buyers-guide-cli-gem/cli.rb, line 80 def more_info(input, array) Headphones::Scraper.more_info(array[input.to_i - 1][:url]) end
select_headphone(array)
click to toggle source
# File lib/headphones-buyers-guide-cli-gem/cli.rb, line 51 def select_headphone(array) puts "Here are the top headphones in the catagory:".colorize(:blue) puts " " generate_list(array) puts "Choose Headphone Number for More Info or Type exit.".colorize(:blue) input = nil while input != "exit" || !input.to_i.between?(1,array.length) input = gets.strip if input.to_i.between?(1, array.length) more_info(input, array) again elsif input.downcase == "exit" goodby else puts "Please choose valid number or type exit".colorize(:red) end end end
start()
click to toggle source
# File lib/headphones-buyers-guide-cli-gem/cli.rb, line 21 def start in_ear_array = Headphones::Scraper.list("https://www.cnet.com/topics/headphones/best-headphones/earbuds/") over_ear_array = Headphones::Scraper.list("https://www.cnet.com/topics/headphones/best-headphones/over-the-ear/") on_ear_array = Headphones::Scraper.list("https://www.cnet.com/topics/headphones/best-headphones/on-ear/") input = nil while input != "exit" || !input.to_i.between?(1,3) input = gets.strip case input when "1" select_headphone(in_ear_array) when "2" select_headphone(over_ear_array) when "3" select_headphone(on_ear_array) when "exit" goodby else puts (<<~EOT).colorize(:red) Please choose valid number or type exit: 1. In-ear 2. Over-ear 3. On-ear EOT end end end