Class: Dredd::Dsl::Aggregate
- Inherits:
-
Object
- Object
- Dredd::Dsl::Aggregate
show all
- Defined in:
- lib/dredd/dsl/aggregate.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/dredd/dsl/aggregate.rb', line 22
def method_missing(meth, *args, &block)
if [:sum, :mean, :min, :max, :size].include?(meth)
@func = meth
@projection = block
else
super
end
end
|
Instance Method Details
#execute(collection) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/dredd/dsl/aggregate.rb', line 8
def execute(collection)
return collection unless @func
arr = if @projection
collection.map{|k| Hashie::Mash.new(k) }
.map{|k| k.instance_eval(&@projection) }
else
(0...collection.size).to_a
end
arr.to_scale.send(@func)
end
|