Class: FWC::Summary
- Inherits:
-
Object
- Object
- FWC::Summary
- Defined in:
- lib/fwc.rb
Instance Method Summary collapse
-
#initialize(matcher) ⇒ Summary
constructor
A new instance of Summary.
- #receive(data) ⇒ Object
- #report! ⇒ Object
Constructor Details
#initialize(matcher) ⇒ Summary
Returns a new instance of Summary.
110 111 112 113 |
# File 'lib/fwc.rb', line 110 def initialize matcher @matcher = matcher @groups = {} end |
Instance Method Details
#receive(data) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# 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! ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# 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 |