class MCollective::Aggregate::Summary - mcollective version 2.12.5

# class MCollective::Aggregate::Summary

### Public Instance Methods

add_value(value) click to toggle source

       # File lib/mcollective/aggregate/summary.rb
    25 def add_value(value)
    26   if @result[:value].keys.include?(value)
    27     @result[:value][value] += 1
    28   else
    29     @result[:value][value] = 1
    30   end
    31 end

process_result(value, reply) click to toggle source

Increments the value field if value has been seen before Else create a new value field

       # File lib/mcollective/aggregate/summary.rb
    15 def process_result(value, reply)
    16   unless value.nil?
    17     if value.is_a? Array
    18       value.map{|val| add_value(val)}
    19     else
    20       add_value(value)
    21     end
    22   end
    23 end

startup_hook() click to toggle source

Before function is run processing

       # File lib/mcollective/aggregate/summary.rb
     5 def startup_hook
     6   @result[:value] = {}
     7   @result[:type] = :collection
     8
     9   # set default aggregate_format if it is undefined
    10   @aggregate_format = :calculate unless @aggregate_format
    11 end

summarize() click to toggle source
Calls superclass method `MCollective::Aggregate::Base#summarize`

       # File lib/mcollective/aggregate/summary.rb
    33 def summarize
    34   if @aggregate_format == :calculate
    35     max_key_length = @result[:value].keys.map do |k|
    36
    37       # Response values retain their types. Here we check
    38       # if the response is a string and turn it into a string
    39       # if it isn't one.
    40       if k.respond_to?(:length)
    41         k.length
    42       elsif k.respond_to?(:to_s)
    43         k.to_s.length
    44       end
    45     end.max
    46     @aggregate_format = "%#{max_key_length}s = %s"
    47   end
    48
    49   super
    50 end