Class: Beanbox::CLI
- Inherits:
-
Object
- Object
- Beanbox::CLI
- Defined in:
- lib/beanbox/cli.rb
Instance Attribute Summary collapse
-
#scraper ⇒ Object
Returns the value of attribute scraper.
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #list_coffees ⇒ Object
- #list_detail(coffee) ⇒ Object
- #list_menu ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
5 6 7 |
# File 'lib/beanbox/cli.rb', line 5 def initialize Beanbox::Coffee.reset! end |
Instance Attribute Details
#scraper ⇒ Object
Returns the value of attribute scraper.
3 4 5 |
# File 'lib/beanbox/cli.rb', line 3 def scraper @scraper end |
Instance Method Details
#list_coffees ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/beanbox/cli.rb', line 16 def list_coffees puts "Hello! Today's top selling coffees are: " Beanbox::Coffee.all.each_with_index do |c, i| puts "#{i + 1}. #{c.name} roasted by #{c.roaster} at #{c.price}" puts end end |
#list_detail(coffee) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/beanbox/cli.rb', line 24 def list_detail(coffee) @scraper.scrape_detail(coffee) puts puts "#{coffee.name} roasted by #{coffee.roaster}" puts "Type: #{coffee.type}" puts "Roast level: #{coffee.roast_level}" puts "Price: #{coffee.price}" puts puts "#{coffee.description}" puts puts 'Enter "list" to return the menu or "exit!"' input = nil until input == "exit!" input = gets.chomp if input == "list" self.list_coffees self. break elsif input == "exit!" exit else puts "I didn't quite get that..." self. end end end |
#list_menu ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/beanbox/cli.rb', line 51 def puts 'Select a number for more information, "exit!", or "list" to return to the menu' input = nil until input == "exit!" input = gets.chomp case input when "1" self.list_detail(Beanbox::Coffee.all[0]) when "2" self.list_detail(Beanbox::Coffee.all[1]) when "3" self.list_detail(Beanbox::Coffee.all[2]) when "4" self.list_detail(Beanbox::Coffee.all[3]) when "5" self.list_detail(Beanbox::Coffee.all[4]) when "6" self.list_detail(Beanbox::Coffee.all[5]) when "7" self.list_detail(Beanbox::Coffee.all[6]) when "8" self.list_detail(Beanbox::Coffee.all[7]) when "9" self.list_detail(Beanbox::Coffee.all[8]) when "10" self.list_detail(Beanbox::Coffee.all[9]) when "list" self.list_coffees self. when "exit!" exit else puts "I didn't quite get that..." self. end end end |
#run ⇒ Object
9 10 11 12 13 14 |
# File 'lib/beanbox/cli.rb', line 9 def run @scraper = Beanbox::Scraper.new("https://beanbox.co/coffee/best-sellers") @scraper.scrape self.list_coffees self. end |