Class: TopGeniusSongs::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



2
3
4
# File 'lib/top_genius_songs/cli.rb', line 2

def call
	start
end

#helpObject



29
30
31
32
# File 'lib/top_genius_songs/cli.rb', line 29

def help
	puts "Type 'list' to list songs, or any number of the song for the lyrics!"
	print ">>  "
end

#listObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/top_genius_songs/cli.rb', line 34

def list
	puts "Songs:"
	TopGeniusSongs::Song.all.each.with_index(1) do |song, index|
		puts "#{index}. \"#{song.title}\" By \"#{song.artist}\""
		print "Description:"
		puts "#{song.description[0..300]}..."
		puts '     -----------------------------         '
		puts ''
	end
end

#startObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/top_genius_songs/cli.rb', line 6

def start
	puts "Hi Welcome to Top Genius Songs!!"
	sleep(1)
	songs = TopGeniusSongs::Scraper.scrape
	list
	input = nil
	help
	while input != 'exit'
		input = gets.chomp
		if input == 'list'
			list
		elsif input.to_i > 0 && input.to_i <= songs.size
			puts "------------ '#{songs[input.to_i-1].title}' Lyrics --------------- "
			sleep(1)
			puts "#{songs[input.to_i-1].lyrics}"
			print ">>  "
		else
			help
		end
	end
	puts "Genius!!!!! we rule!"
end