Class: Soundly::CLI

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

Instance Method Summary collapse

Instance Method Details

#blue_pillObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/soundly/cli.rb', line 77

def blue_pill
	print "\n"
	puts "Blue Pill: Main Menu"
	blue_playlist

	user_input = nil
	while user_input != "menu" #Add functionality for "main menu" or "2" to get back to main menu
		user_input = gets.downcase.strip
		if user_input == "menu"
			menu
		elsif user_input == "exit"
			goodbye
		elsif (1..50).to_a.include?(user_input.to_i)
			puts " "
			puts "Here are details on #{@@pills.blue_songs[user_input.to_i-1].name}"
			song = @@pills.blue_songs[user_input.to_i-1]
			puts "Song name:   #{song.name}"
			puts "Artist:      #{song.artists[0].name}"
			puts "Album:       #{song.album.name}"
			puts "Duration:    #{song.duration_ms}"
			puts "Popularity:  #{song.popularity}"
			puts "Preview_url: #{song.preview_url}" if song.preview_url != nil
			puts " "
			puts "Would you like to select another song, Main Menu or Exit?"
		else
			puts %(Try again.)
			puts " "
			puts %(Select a number from the list, Menu or Exit)
			puts " "
		end
	end
end

#blue_playlistObject



68
69
70
71
72
73
74
75
# File 'lib/soundly/cli.rb', line 68

def blue_playlist
	puts %Q(America's top 50, coming up...)
	puts "\n"
	@@pills.blue_songs.each.with_index(1) do |song, song_index| 
		puts "#{song_index}.  #{song.name} by #{song.artists[0].name}"
	end
		inner_playlist_options
end

#goodbyeObject



146
147
148
149
# File 'lib/soundly/cli.rb', line 146

def goodbye
	puts %Q(Peace out.)
	exit
end

#greetingsObject



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

def greetings
	puts %Q(Hey there...)
	print %Q(You like music?)
	puts %Q( Cool, me too.)
	print "\n"
end

#inner_playlist_optionsObject



51
52
53
54
55
56
57
# File 'lib/soundly/cli.rb', line 51

def inner_playlist_options
	puts " "
	puts %Q(Type a song's listing number to learn more.)
	puts %Q(Type "Menu" to head back to the main menu.)
	puts %Q(Type exit to peace out.)
	puts " "
end


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/soundly/cli.rb', line 23

def menu
	user_input = nil

	greetings
	puts Rainbow("Main Menu").green
	puts Rainbow("Blue Pill").blue + " or" + Rainbow(" Red Pill").red + " or Exit?"

	while user_input != "exit"
		user_input = gets.strip.downcase
		if user_input == "exit" || user_input == "3"
			goodbye
		elsif user_input == "blue" || user_input == "blue pill" || user_input == "1"
			blue_pill
		elsif user_input == "red" || user_input == "red pill" || user_input == "2"
			red_pill
		else
			puts "Come again?"
		end
	end
end

#pass_goObject



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

def pass_go
	if !up?
		puts "You need an internet connection to run this program..."
		puts "As if I needed to tell you that."
		puts "Good bye for now, human."
		exit
	else
		@@pills = Soundly::Tracks.new
		menu
	end
end

#red_pillObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/soundly/cli.rb', line 110

def red_pill
	puts " "
	puts %Q((I like your style human.))
	puts "Red Pill: Main Menu"
	red_playlist

	user_input = nil
	while user_input != "menu" #Add functionality for "main menu" or "2" to get back to main menu
		user_input = gets.strip
		object = @@pills.red_songs.count.to_i

		if user_input == "menu"
			menu
		elsif user_input == "exit"
			goodbye
		elsif (1..object).include?(user_input.to_i)
			puts " "
			puts "Here are details on #{@@pills.red_songs[user_input.to_i-1].name}"
			song = @@pills.red_songs[user_input.to_i-1]
			puts "Song name:   #{song.name}"
			puts "Artist:      #{song.artists[0].name}"
			puts "Album:       #{song.album.name}"
			puts "Duration:    #{song.duration_ms}"
			puts "Popularity:  #{song.popularity}"
			puts "Preview_url: #{song.preview_url}" if song.preview_url != nil
			print "\n"
			puts "Would you like to select another song, go back to the Main Menu or Exit?"
		else
			puts %(Try again.)
			print " \n"
			puts %(Select a number from the list, "Menu" or "Exit")
			print "\n"
		end
	end
end

#red_playlistObject



59
60
61
62
63
64
65
66
# File 'lib/soundly/cli.rb', line 59

def red_playlist
	puts " "
	puts %Q(Heres what I am currently listening to.)
	@@pills.red_songs.each.with_index(1) do |song, song_index| 
		puts "#{song_index}.  #{song.name} by #{song.artists[0].name} \n"
	end
	inner_playlist_options
end

#startObject



19
20
21
# File 'lib/soundly/cli.rb', line 19

def start
	pass_go
end

#up?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/soundly/cli.rb', line 3

def up?
	true if Net::Ping::External.new("www.google.com").ping?
end