Class: NYCTheaterDiscounts::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/nyc_theater_discounts/cli.rb

Instance Method Summary collapse

Instance Method Details

#by_show_menuObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/nyc_theater_discounts/cli.rb', line 69

def by_show_menu
  puts "Please enter the title of the show you would like to check:"
  input = gets.strip
  input.to_s
  NYCTheaterDiscounts::Vendor.all.each do |vendor|
    vendor.shows.each do |show|
      if show.name.downcase.include? input.downcase
        puts "At #{vendor.name}: #{show.name} -- available from: #{show.price}"
        puts "**to see this offer visit: #{show.deal_url}**\n\n"
      end
    end
  end
  puts "We did not find any additional shows associated with your query."
end

#by_vendor_menuObject



61
62
63
64
65
66
67
# File 'lib/nyc_theater_discounts/cli.rb', line 61

def by_vendor_menu
  list_vendors
  puts "Please enter the number of the discount source you would like to check:"
  input = gets.to_i
  vendor = NYCTheaterDiscounts::Vendor.all[input-1]
  list_deals(vendor)
end

#callObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/nyc_theater_discounts/cli.rb', line 6

def call
  puts "*** Loading Deals ***"
  NYCTheaterDiscounts::Scraper.load_TodayTix
  NYCTheaterDiscounts::Scraper.load_Theatermania
  NYCTheaterDiscounts::Scraper.load_BroadwayBox
  puts "Hello theater nerd! Here are the discount sources available today:"
  list_vendors
  puts "To see a list of deals for each vendor type the number of the vendor. To search by show type 'by show'. To quit, type 'exit'."
  starting_menu
  goodbye
end

#goodbyeObject



84
85
86
# File 'lib/nyc_theater_discounts/cli.rb', line 84

def goodbye
  puts "Thank you for using nyc-theater-discounts. Check back again tomorrow!"
end

#list_deals(vendor) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/nyc_theater_discounts/cli.rb', line 53

def list_deals(vendor)
  puts "\nTo visit #{vendor.name} go to: #{vendor.url}\n\n"
  vendor.shows.each_with_index do |show, index|
    puts "#{index+1}. #{show.name} -- available from: #{show.price}"
    puts "**to see this offer visit: #{show.deal_url}**\n\n"
  end
end

#list_vendorsObject



49
50
51
# File 'lib/nyc_theater_discounts/cli.rb', line 49

def list_vendors
  NYCTheaterDiscounts::Vendor.all.each_with_index {|value, index| puts "#{index+1}. #{value.name}"}
end


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nyc_theater_discounts/cli.rb', line 32

def menu(input)
  until input.to_s.downcase == "exit"
    if input.to_s.downcase == "by vendor"
      by_vendor_menu
      puts "To see more deals search either 'by vendor' or 'by show'. To quit type 'exit'."
      input = gets.strip
    elsif input.to_s.downcase == "by show"
      by_show_menu
      puts "To see more deals search either 'by vendor' or 'by show'. To quit type 'exit'."
      input = gets.strip
    else
      puts "Please choose either 'by vendor' or 'by show'. To quit type 'exit'."
      input = gets.strip
    end
  end
end

#starting_menuObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nyc_theater_discounts/cli.rb', line 18

def starting_menu
  input = gets.strip
  if input.to_i == 1 || input.to_i == 2 || input.to_i == 3
    vendor = NYCTheaterDiscounts::Vendor.all[input.to_i-1]
    list_deals(vendor)
    puts "To see more deals search either 'by vendor' or 'by show'. To quit type 'exit'."
    input = gets.strip
    menu(input)
  else 
    menu(input)
  end
  
end