class Git::Stats::Statistic

Attributes

branch[RW]
folder[RW]
options[RW]

Public Class Methods

new(folder, branch, options = {}) click to toggle source
# File lib/git/stats/statistic.rb, line 9
def initialize(folder, branch, options = {})
  # TODO: Check folder
  @folder = folder
  # TODO: Check branch
  @branch = branch || "develop"
  @options = options
end
statistic(folder, branch, options = {}) click to toggle source
# File lib/git/stats/statistic.rb, line 55
def statistic(folder, branch, options = {})
  new(folder, branch, options).statistic
end

Public Instance Methods

filter_commits() click to toggle source
# File lib/git/stats/statistic.rb, line 43
def filter_commits
  repo = Repo.new(@folder, @branch)
  commits = repo.commits

  if options[:start_date]
    commits = commits.select { |commit| commit.date >= options[:start_date] }
  end

  commits
end
statistic() click to toggle source
# File lib/git/stats/statistic.rb, line 17
def statistic
  result = {}

  stats = filter_commits.group_by { |commit| commit.author_email }
  stats.each do |author, commits|
    month_stats = commits.group_by { |c| c.date.strftime("%Y-%m") }
    info = {}
    month_stats.each do |month, value|
      info[month] = {
        commits: value.length,
        files: 0,
        insertions: 0,
        deletions: 0
      }
      value.each do |c|
        info[month][:files] += c.stats[:files]
        info[month][:insertions] += c.stats[:insertions]
        info[month][:deletions] += c.stats[:deletions]
      end
    end
    result[author] = info
  end

  result
end