class MCollective::Aggregate::Summary

Public Instance Methods

add_value(value) click to toggle source
# File lib/mcollective/aggregate/summary.rb, line 25
def add_value(value)
  if @result[:value].keys.include?(value)
    @result[:value][value] += 1
  else
    @result[:value][value] = 1
  end
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, line 15
def process_result(value, reply)
  unless value.nil?
    if value.is_a? Array
      value.map{|val| add_value(val)}
    else
      add_value(value)
    end
  end
end
startup_hook() click to toggle source

Before function is run processing

# File lib/mcollective/aggregate/summary.rb, line 5
def startup_hook
  @result[:value] = {}
  @result[:type] = :collection

  # set default aggregate_format if it is undefined
  @aggregate_format = :calculate unless @aggregate_format
end
summarize() click to toggle source
Calls superclass method MCollective::Aggregate::Base#summarize
# File lib/mcollective/aggregate/summary.rb, line 33
def summarize
  if @aggregate_format == :calculate
    max_key_length = @result[:value].keys.map do |k|

      # Response values retain their types. Here we check
      # if the response is a string and turn it into a string
      # if it isn't one.
      if k.respond_to?(:length)
        k.length
      elsif k.respond_to?(:to_s)
        k.to_s.length
      end
    end.max
    @aggregate_format = "%#{max_key_length}s = %s"
  end

  super
end