Class: MARS::Aggregator

Inherits:
Runnable show all
Defined in:
lib/mars/aggregator.rb

Instance Attribute Summary collapse

Attributes inherited from Runnable

#formatter, #name, #state

Instance Method Summary collapse

Methods inherited from Runnable

formatter, step_name

Methods included from Hooks

included, #run_after_hooks, #run_before_hooks

Constructor Details

#initialize(name = "Aggregator", operation: nil, **kwargs) ⇒ Aggregator

Returns a new instance of Aggregator.



7
8
9
10
11
# File 'lib/mars/aggregator.rb', line 7

def initialize(name = "Aggregator", operation: nil, **kwargs)
  super(name: name, **kwargs)

  @operation = operation || ->(inputs) { inputs }
end

Instance Attribute Details

#operationObject (readonly)

Returns the value of attribute operation.



5
6
7
# File 'lib/mars/aggregator.rb', line 5

def operation
  @operation
end

Instance Method Details

#run(context) ⇒ Object



13
14
15
16
# File 'lib/mars/aggregator.rb', line 13

def run(context)
  context = ensure_context(context)
  operation.call(context.current_input)
end