Class: OnTapIbc::CLI
- Inherits:
-
Object
- Object
- OnTapIbc::CLI
- Defined in:
- lib/on_tap_ibc/cli.rb
Constant Summary collapse
- @@five =
[]
- @@nofive =
[]
Instance Method Summary collapse
- #display_profile(selected_tap) ⇒ Object
- #list_beers ⇒ Object
- #make_beers ⇒ Object
- #new_selection ⇒ Object
- #select_tap(sorted_tap_arr) ⇒ Object
- #sort_beers ⇒ Object
- #start ⇒ Object
- #welcome ⇒ Object
- #wrap(s, width = 100) ⇒ Object
Instance Method Details
#display_profile(selected_tap) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/on_tap_ibc/cli.rb', line 65 def display_profile(selected_tap) puts "-----------------------------------------" puts "#{selected_tap.name.upcase}" puts "-----------------------------------------" if selected_tap.long_desc == nil puts wrap("DESCRIPTION #{selected_tap.short_desc}") puts "ABV #{selected_tap.abv}" puts "HOPS N/A" puts "DRY HOPS N/A" puts "MALTS N/A" else puts "STYLE #{selected_tap.style}" puts wrap("DESCRIPTION #{selected_tap.long_desc}") selected_tap.addl1.each {|i| puts "#{i}"} end new_selection end |
#list_beers ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/on_tap_ibc/cli.rb', line 32 def list_beers puts "\#. BEER - ABV %" puts "-----------------------------------------" puts "Flagship and Seasonal Beers" @@nofive.map.with_index(1) do |beer, index| puts "#{index}. #{beer.name} - #{beer.abv}" end puts "-----------------------------------------" puts "5 Barrel Brews" @@five.map.with_index(@@nofive.length + 1) do |beer, index| puts "#{index}. #{beer.name} - #{beer.abv}" end puts "-----------------------------------------" puts "Select a tap number to learn more about the beer." sorted_tap_arr = (@@nofive + @@five).flatten select_tap(sorted_tap_arr) end |
#make_beers ⇒ Object
21 22 23 24 |
# File 'lib/on_tap_ibc/cli.rb', line 21 def make_beers current_beers = OnTapIbc::Scraper. OnTapIbc::Beer.(current_beers) end |
#new_selection ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/on_tap_ibc/cli.rb', line 83 def new_selection puts "-----------------------------------------" puts "Type list to select another beer or exit." input = nil input = gets.strip.downcase if input == "list" list_beers elsif input == "exit" puts "Cheers!" exit else puts "Please try again." end end |
#select_tap(sorted_tap_arr) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/on_tap_ibc/cli.rb', line 50 def select_tap(sorted_tap_arr) input = nil while input != "exit" input = gets.strip.downcase if input.to_i > 0 && input.to_i <= sorted_tap_arr.length selected_tap = sorted_tap_arr[input.to_i-1] OnTapIbc::Beer.assign_beer(selected_tap) display_profile(selected_tap) else puts "Invalid tap number. Please try again." end end end |
#sort_beers ⇒ Object
26 27 28 29 30 |
# File 'lib/on_tap_ibc/cli.rb', line 26 def sort_beers OnTapIbc::Beer.all.each do |beer| beer.short_desc.include?("5BBL") ? @@five << beer : @@nofive << beer end end |
#start ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/on_tap_ibc/cli.rb', line 6 def start welcome make_beers sort_beers list_beers goodbye end |
#welcome ⇒ Object
14 15 16 17 18 19 |
# File 'lib/on_tap_ibc/cli.rb', line 14 def welcome puts "-----------------------------------------" puts "What's on tap at Ithaca Beer Company" puts "#{OnTapIbc::Scraper.updated_last}" puts "-----------------------------------------" end |
#wrap(s, width = 100) ⇒ Object
98 99 100 |
# File 'lib/on_tap_ibc/cli.rb', line 98 def wrap(s, width=100) s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n") end |