Class: Twigg::Gerrit::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/twigg-gerrit/gerrit/tag.rb

Overview

Stats for “@” tags.

Class Method Summary collapse

Class Method Details

.stats(days: 7) ⇒ Object

Returns a hash of “@” tag stats for the last ‘days` days.

Within the hash there are 3 key-value pairs:

- :from: a hash of "from" authors; each author has its own hash of
   tags and counts
- :to: a hash of "to" authors; again with a subhash for each author
- :global: a hash of all tags and their counts


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/twigg-gerrit/gerrit/tag.rb', line 15

def stats(days: 7)
  {
    from:   Hash.new { |h, k| h[k] = Hash.new(0) },
    to:     Hash.new { |h, k| h[k] = Hash.new(0) },
    global: Hash.new(0),
  }.tap do |stats|
    (change_messages(days) + comment_messages(days)).each do |result|
      tags_from_result(result[:message]).each do |tag, count|
        [
          stats[:from][result[:from_full_name]],
          stats[:to][result[:to_full_name]],
          stats[:global],
        ].each do |hash|
          hash[tag] += count
        end
      end
    end
  end
end