1module MCollective
2  class Aggregate
3    class Boolean_summary<Base
4      def startup_hook
5        @result[:value] = {}
6        @result[:type] = :collection
7
8        # set default aggregate_format if it is undefined
9        @arguments = {true => 'True', false => 'False'} unless @arguments
10
11        # Support boolean and symbol arguments
12        @arguments[true] = @arguments.delete(:true) if @arguments.include?(:true)
13        @arguments[false] = @arguments.delete(:false) if @arguments.include?(:false)
14
15        @aggregate_format = "%5s = %s" unless @aggregate_format
16      end
17
18      # Increments the value field if value has been seen before
19      # Else create a new value field
20      def process_result(value, reply)
21        unless value.nil?
22          if value.is_a? Array
23            value.map{|val| add_value(val)}
24          else
25            add_value(value)
26          end
27        end
28      end
29
30      # Transform the true or false value into the replacement string
31      def add_value(value)
32        if @result[:value].keys.include?(@arguments[value])
33          @result[:value][@arguments[value]] += 1
34        else
35          @result[:value][@arguments[value]] = 1
36        end
37      end
38    end
39  end
40end
41