Class: LoopermanSamples::CLI
- Inherits:
-
Object
- Object
- LoopermanSamples::CLI
- Defined in:
- lib/looperman_samples/cli.rb
Constant Summary collapse
- @@sample_list =
class variable so CLI play function can
[]
Instance Method Summary collapse
- #call ⇒ Object
- #goodbye ⇒ Object
- #main_menu ⇒ Object
-
#play ⇒ Object
controls the play sequence.
Methods included from CliMethods::Listable
#list_all_samples_by_creator, #list_by_downloads, #list_by_key, #list_by_tempo
Methods included from CliMethods::Scrapeable
Methods included from CliMethods::Findable
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 |
# File 'lib/looperman_samples/cli.rb', line 14 def call scrape play goodbye end |
#goodbye ⇒ Object
73 74 75 |
# File 'lib/looperman_samples/cli.rb', line 73 def goodbye puts "see you tomorrow for more samples!" end |
#main_menu ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/looperman_samples/cli.rb', line 21 def puts "There are 25 new samples today. how would you like to browse?" puts "1. browse samples by key" puts "2. browse samples by tempo" puts "3. browse samples by download count" input = gets.strip if input == "1" list_by_key #prints list and sets @@sample_list variable @@sample_list = LoopermanSamples::Sample.sort_by_key elsif input == "2" list_by_tempo #prints list and sets @@sample_list variable @@sample_list = LoopermanSamples::Sample.sort_by_tempo elsif input == "3" list_by_downloads #prints list and sets @@sample_list variable @@sample_list = LoopermanSamples::Sample.sort_by_download_count else puts "sorry, not sure what you want" end end |
#play ⇒ Object
controls the play sequence
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 |
# File 'lib/looperman_samples/cli.rb', line 46 def play input = nil loop do puts "please enter the number of the sample you'd like to listen to or type exit:" input = gets.strip if input.to_i < @@sample_list.size + 1 && input.to_i > 0 #checks that input is greater than zero and less than list size sample = @@sample_list[input.to_i - 1] #takes user input, and sets sample variable using index lookup puts "You're listening to #{sample.title} by #{sample.creator.name}" puts "would you like to hear more from #{sample.creator.name}? (type yes or no)" input = gets.strip if input == "yes" puts "More by #{sample.creator.name}" @@sample_list = find_all_by_creator(sample) list_all_samples_by_creator(@@sample_list) elsif input == "no" end elsif input.to_i > LoopermanSamples::Sample.all.size puts "please enter a lower number" elsif input == "back" else break end end end |