Class: CLI

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

Class Method Summary collapse

Class Method Details

.display_characters ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/star_wars_finder/cli.rb', line 11

def self.display_characters
	Character.top_10
	puts "\nSelect a character in this top 10 list or,\nsearch for a character by name"
	puts "Type 'exit' to exit\n\n"
	name = gets.strip.downcase
	if name == "exit"
		exit!
	elsif Character.has_name?(name) == false && name.to_i == 0.0
		puts "The name you listed is not available"
		sleep(1.25)
		self.display_characters
	else
		puts "Entry is not valid"
		sleep(1.25)
		self.display_characters
	end
end

.display_search_res(character) ⇒ Object



28
29
30
31
32
33
# File 'lib/star_wars_finder/cli.rb', line 28

def self.display_search_res(character)
	character.instance_variables.each.with_index do |m,i|
		puts "#{character.instance_variables[i].to_s.gsub("@", "")}: #{character.send(m.to_s.gsub("@", ""))}"
	end
	self.exit?
end

.exit? ⇒ Boolean

Returns:

  • (Boolean)


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

def self.exit?
	puts "\nSearch again? y/n"
	input = gets.strip.downcase
	if input == 'y'
		self.display_characters
	elsif input != 'n'
		puts "invalid choice"
		self.exit?
	else
		exit!
	end
end

.start ⇒ Object



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

def self.start
	self.welcome
	self.display_characters
end

.welcome ⇒ Object



6
7
8
9
10
# File 'lib/star_wars_finder/cli.rb', line 6

def self.welcome
	puts "Welcome to my Star Wars Gem! \n\n"
	sleep(2)
	puts "You will be able to see a list of characters and some info about them\n\n"
end