Class: Meditation::CLI_controller

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

Instance Method Summary collapse

Instance Method Details

#callObject

initialize the CLI controller object – wrap my brain around this.



3
4
5
6
7
8
9
10
# File 'lib/meditation/cli.rb', line 3

def call #initialize the CLI controller object -- wrap my brain around this. 
 	#scrape first 
 	puts "****   Welcome to Miriam's meditation gem.  ****"
 	puts "************************************************"

 	@today = Meditation::Scraper.new.scrape
 	menu
end

#list_meditationsObject



42
43
44
45
46
47
48
49
# File 'lib/meditation/cli.rb', line 42

def list_meditations 	
	@today.meditations.each_with_index do |m, i|
		puts "#{i + 1}: #{m.title}"
		puts " by #{m.teacher} (Length: #{m.length})"
	end 
	puts "************************************************"

end


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/meditation/cli.rb', line 13

def menu
	list_or_exit_input = ""

	while list_or_exit_input != "exit"
		puts "Enter 'list' to see five Audio Dharma meditations, or 'exit' to leave."
		list_or_exit_input = gets.strip.downcase

		#logic for the input: 
		if list_or_exit_input == "list"
			puts "************************************************"
			list_meditations 

			puts "Enter the number of the meditative talk you'd like to hear. (It'll auto-open in your browser.)"
			pick_meditation
			

		elsif list_or_exit_input == "exit"
			puts "Have a calm and grounded day."
			puts "*****************************"
			break

		else
			puts "Can you repeat that?"

		end
	end
end

#pick_meditationObject



51
52
53
54
55
# File 'lib/meditation/cli.rb', line 51

def pick_meditation
		selected_meditation = gets.strip
		puts "http://www.audiodharma.org/#{@today.meditations[selected_meditation.to_i-1].stream}"
		system("open http://www.audiodharma.org/#{@today.meditations[selected_meditation.to_i-1].stream}")
end