-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_interface.rb
59 lines (50 loc) · 1.42 KB
/
user_interface.rb
1
2
3
4
5
6
7
8
9
10
11
12
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require_relative 'search_engine'
require_relative 'data_handler'
class UserInterface
attr_accessor :data_handler
def initialize
@data_handler = DataHandler.new
@data_handler.import
end
def launch!
introduction
result = nil
until result == 'quit'
search_string = search_value
result = do_action(search_string)
end
conclusion
end
private
def search_value
puts 'Enter a search value:'
user_response = gets.chomp
end
def do_action(search_string)
unless search_string == 'quit'
returned_data = @data_handler.search_engine.find(search_string)
print_data(returned_data)
end
search_string
end
def print_data(data)
if data.count.zero?
puts 'No results!'
else
puts "Your search returned #{data.count} result(s):"
puts '-----------------------------------------------------'
data.each do |hash|
puts "Data Type: #{hash[:data_set_name].split(' ').map(&:capitalize).join(' ')}"
puts(hash.map { |k, v| "#{k}: #{v}" }.sort)
puts '-----------------------------------------------------'
end
end
end
def introduction
puts "\n\n<<< Welcome to the project and user search engine >>>\n\n"
puts "This is a search engine to help you search for projects and users. Type 'quit' at any time to exit.\n\n"
end
def conclusion
puts "\n\n<<< Thank you for using the search engine >>>\n\n"
end
end