class FWC::Summary

Public Class Methods

new(matcher) click to toggle source
# File lib/fwc.rb, line 110
def initialize matcher
  @matcher = matcher
  @groups = {}
end

Public Instance Methods

receive(data) click to toggle source
# File lib/fwc.rb, line 133
def receive data
  return if not @matcher.matches? data

  id = [data["id"], data["type"]]
  group = (@groups[id] ||= {:id => data["id"], :type => data["type"],
                            :items => {}})

  key = data["data"]["key"]
  items = group[:items]

  if v = items[key]
    items[key] = v + 1
  else
    items[key] = 1
  end
end
report!() click to toggle source
# File lib/fwc.rb, line 115
def report!
  return if @groups.empty?

  FWC.log.info "Summary Report:"

  @groups.sort.each do |id, group|
    items = group[:items].to_a

    FWC.log.info "  #{group[:id]} (#{group[:type]})"
    items.sort.each do |key, count|
      key = "<nil>" if key.nil?
      FWC.log.info "    #{key} #{count}"
    end
  end

  @groups = {}
end