Sha256: 2277689abbc889d046f661b00635b9702e86b411c91bccdb14e8f23626a769df

Contents?: true

Size: 963 Bytes

Versions: 10

Compression:

Stored size: 963 Bytes

Contents

# frozen_string_literal: true

module GitFame
  class Collector
    extend Dry::Initializer

    option :filter, type: Filter
    option :diff, type: Types::Any

    # @return [Collector]
    def call
      Result.new(contributions: contributions)
    end

    private

    def contributions
      commits = Hash.new { |h, k| h[k] = Set.new }
      files = Hash.new { |h, k| h[k] = Set.new }
      lines = Hash.new(0)
      names = {}

      diff.each do |change|
        filter.call(change) do |loc, file, oid, name, email|
          commits[email].add(oid)
          files[email].add(file)
          names[email] = name
          lines[email] += loc
        end
      end

      lines.each_key.map do |email|
        Contribution.new({
          lines: lines[email],
          commits: commits[email],
          files: files[email],
          author: {
            name: names[email],
            email: email
          }
        })
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
git_fame-3.2.7 lib/git_fame/collector.rb
git_fame-3.2.5 lib/git_fame/collector.rb
git_fame-3.2.2 lib/git_fame/collector.rb
git_fame-3.2.1 lib/git_fame/collector.rb
git_fame-3.1.1 lib/git_fame/collector.rb
git_fame-3.1.0 lib/git_fame/collector.rb
git_fame-3.0.3 lib/git_fame/collector.rb
git_fame-3.0.2 lib/git_fame/collector.rb
git_fame-3.0.1 lib/git_fame/collector.rb
git_fame-3.0.0 lib/git_fame/collector.rb