Class: LoopermanSamples::CLI
- Inherits:
-
Object
- Object
- LoopermanSamples::CLI
- Defined in:
- lib/looperman_samples/cli.rb
Overview
our CLI controller
Instance Method Summary collapse
- #call ⇒ Object
- #goodbye ⇒ Object
- #main_menu ⇒ Object
- #more_samples_by_creator(sample) ⇒ Object
-
#play ⇒ Object
controls the play sequence.
Instance Method Details
#call ⇒ Object
5 6 7 8 9 10 |
# File 'lib/looperman_samples/cli.rb', line 5 def call LoopermanSamples::SampleScraper.scrape_samples play goodbye end |
#goodbye ⇒ Object
70 71 72 |
# File 'lib/looperman_samples/cli.rb', line 70 def goodbye puts "see you tomorrow for more samples!" end |
#main_menu ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/looperman_samples/cli.rb', line 12 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" LoopermanSamples::Sample.list_samples_by_key $sample_list = LoopermanSamples::Sample.all.sort {|a, b| a.key <=> b.key} elsif input == "2" LoopermanSamples::Sample.list_samples_by_tempo $sample_list = LoopermanSamples::Sample.all.sort {|a, b| b.bpm.to_i <=> a.bpm.to_i} elsif input == "3" LoopermanSamples::Sample.list_samples_by_download_count $sample_list = LoopermanSamples::Sample.all.sort {|a, b| b.download_count.to_i <=> a.download_count.to_i} else puts "sorry, not sure what you want" end end |
#more_samples_by_creator(sample) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/looperman_samples/cli.rb', line 59 def more_samples_by_creator(sample) # sets $samples_by_creator to equal a collection of samples by given creator LoopermanSamples::SampleScraper.scrape_more_samples_by_creator(sample.creator) # displays a numbered list of those samples LoopermanSamples::Creator.list_all_samples_by_creator #what is this # sets the sample list to be used in play mode $sample_list = $samples_by_creator end |
#play ⇒ Object
controls the play sequence
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/looperman_samples/cli.rb', line 34 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 # binding.pry sample = $sample_list[input.to_i - 1] 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" more_samples_by_creator(sample) elsif input == "no" end # puts "Ok!" elsif input.to_i > LoopermanSamples::Sample.all.size puts "please enter a lower number" else break end end end |