-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.rb
50 lines (38 loc) · 1.04 KB
/
search.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
require 'data_parser'
require 'elements'
require 'queue'
$LOAD_PATH << './'
module EventReporter
class Search
attr_accessor :results
def initialize
@@results = []
end
def self.results
@@results
end
def self.for(parameters)
attribute = parameters[0]
criteria = parameters[1..-1].join(" ")
@@results = []
if DataParser.loaded_data.empty?
puts "No data has been loaded. Please load data using the [ load ] command."
else
DataParser.loaded_data.select do |dataline|
if dataline.respond_to?(attribute.to_sym) && dataline.send(attribute.to_sym).downcase == criteria.downcase
@@results << dataline
end
end
if @@results.size >= 1
Queue.current_queue = @@results
puts "Seach results loaded to the queue."
else
puts "No search results matched your criteria"
end
end
end
def self.valid_parameters_for_find?(parameters)
parameters.count > 1
end
end
end