Class: Exhibitionist::CLI
- Inherits:
-
Object
- Object
- Exhibitionist::CLI
- Defined in:
- lib/exhibitionist/cli.rb
Instance Method Summary collapse
- #all_shows ⇒ Object
- #call ⇒ Object
- #choose_again ⇒ Object
- #choose_by_museum ⇒ Object
- #choose_exhibition ⇒ Object
- #display_shows ⇒ Object
- #exit ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
3 4 5 6 7 8 9 |
# File 'lib/exhibitionist/cli.rb', line 3 def initialize puts "Welcome to The Exhibitionist.\n" puts "Finding shows...\n\n" Exhibitionist::Shows.scrape_all end |
Instance Method Details
#all_shows ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/exhibitionist/cli.rb', line 95 def all_shows puts "All Current Exhibitions:" Exhibitionist::Shows.sort_by_closing_date.each.with_index(1) do |show, index| puts "#{index}. #{show.title}" end choose_exhibition end |
#call ⇒ Object
11 12 13 14 15 16 |
# File 'lib/exhibitionist/cli.rb', line 11 def call display_shows choose_exhibition #exit end |
#choose_again ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/exhibitionist/cli.rb', line 77 def choose_again puts "Would you like to learn about another show? (Y/N)" input = gets.strip.downcase if input == "y" call elsif input == "n" or input == "exit" exit else puts "I couldn't understand that. Please enter Y or N." choose_again end end |
#choose_by_museum ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/exhibitionist/cli.rb', line 103 def choose_by_museum Exhibitionist::Museums.all.each.with_index(1) do |museum, index| puts "#{index}. #{museum.name}" end puts "\nWhich museum would you like to view? Or type 'back' to see the master exhibition list." input = gets.strip.downcase if input.to_i > 0 input = input.to_i - 1 puts "\n\nShows at the #{Exhibitionist::Museums.all[input].name}:\n\n" Exhibitionist::Shows.sort_by_closing_date.each.with_index(1) do |show, index| if show.museum.name == Exhibitionist::Museums.all[input].name puts show.title show.on_view_through end end choose_again elsif input == "back" call else puts "I could't understand that." choose_again end end |
#choose_exhibition ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 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 73 74 75 |
# File 'lib/exhibitionist/cli.rb', line 32 def choose_exhibition puts "Pick a show you're interested in, or type 'all' to see a list of every exhibition." puts "You can also type 'museums' to see a list of museums currently represented." input = gets.strip.downcase if input.to_i > 0 input = input.to_i - 1 exhibit = Exhibitionist::Shows.sort_by_closing_date[input] puts "\n\n#{exhibit.title}\n\n" puts "at the #{exhibit.museum.name}\n\n" exhibit.closing_info #puts "Closes on #{exhibit.closing_date}\n\n" #puts "#{exhibit.closing_soon_alert}#{exhibit.days_left} days left to see this show!\n\n" puts "\n\nOther shows at this museum:\n\n" Exhibitionist::Shows.all.each.with_index(1) do |show, index| if show.museum.name == exhibit.museum.name && show.title != exhibit.title puts show.title show.on_view_through else end end choose_again elsif input == "museums" puts "The following museums are currently represented:\n\n" choose_by_museum elsif input == "all" all_shows elsif input == "exit" exit else puts "I couldn't understand that." choose_exhibition end end |
#display_shows ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/exhibitionist/cli.rb', line 20 def display_shows Exhibitionist::Shows.sort_by_closing_date.first(10).each.with_index(1) do |show, index| puts "#{index}. #{show.title}" end puts "\nHere are 10 shows closing soon, listed by which is closing soonest.\n\n" end |
#exit ⇒ Object
91 92 93 |
# File 'lib/exhibitionist/cli.rb', line 91 def exit puts "Goodbye! Check back soon for updated shows." end |