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
60
61
62
63
64
65
66
|
# File 'lib/expressions/function_expression.rb', line 12
def build_arel(arel_table)
arguments = @arguments.map { |each| each.build_arel(arel_table) }
case @function
when "count:"
return arguments.first.count()
when "first:"
object = @arguments.first.build_arel(arel_table)
raise "first:(#{object}) not supported by Arel"
return object
when "last:"
object = @arguments.first.build_arel(arel_table)
raise "last::(#{object}) not supported by Arel"
return object
when "fromObject:index:"
object = @arguments.first.build_arel(arel_table)
index = @arguments.second.build_arel (arel_table)
raise "fromObject:(#{object})index:(#{index}) not supported by Arel"
return object[index]
when "add:to:"
return arguments.reduce(:+)
when "from:substract:"
return arguments.reduce(:-)
when "multiply:by:"
return arguments.reduce(:*)
when "divide:by:"
return arguments.reduce(:/)
when "raise:to:"
return arguments.reduce(:**)
else
raise "Unknown function #{@function} #{arguments}"
end
end
|