Class: MCollective::Aggregate::Average
- Defined in:
- lib/mcollective/aggregate/average.rb
Instance Attribute Summary
Attributes inherited from Base
#action, #aggregate_format, #arguments, #name, #output_name, #result
Instance Method Summary collapse
-
#process_result(value, reply) ⇒ Object
Determines the average of a set of numerical values.
-
#startup_hook ⇒ Object
Before function is run processing.
-
#summarize ⇒ Object
Stops execution of the function and returns a ResultObject.
Methods inherited from Base
Constructor Details
This class inherits a constructor from MCollective::Aggregate::Base
Instance Method Details
#process_result(value, reply) ⇒ Object
Determines the average of a set of numerical values
16 17 18 19 |
# File 'lib/mcollective/aggregate/average.rb', line 16 def process_result(value, reply) @result[:value] += value @count += 1 end |
#startup_hook ⇒ Object
Before function is run processing
5 6 7 8 9 10 11 12 13 |
# File 'lib/mcollective/aggregate/average.rb', line 5 def startup_hook @result[:value] = 0 @result[:type] = :numeric @count = 0 # Set default aggregate_function if it is undefined @aggregate_format = "Average of #{@result[:output]}: %f" unless @aggregate_format end |
#summarize ⇒ Object
Stops execution of the function and returns a ResultObject
22 23 24 25 26 |
# File 'lib/mcollective/aggregate/average.rb', line 22 def summarize @result[:value] /= @count result_class(:numeric).new(@result, @aggregate_format, @action) end |