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
|
# File 'motion-prime/models/_filter_mixin.rb', line 3
def filter_array(data, find_options = {}, sort_options = nil)
data = data.select do |entity|
find_options.all? do |field, value|
if value.is_a?(Array)
value.include?(entity.info[field].to_s)
else
entity.info[field] == value
end
end
end if find_options.present?
data.sort! do |a, b|
left_part = []
right_part = []
sort_options[:sort].each do |(k,v)|
left = a.send(k)
right = b.send(k)
if left.class != right.class
left = left.to_s
right = right.to_s
end
left, right = right, left if v.to_s == 'desc'
left_part << left
right_part << right
end
left_part <=> right_part
end if sort_options.try(:[], :sort).present?
data
end
|