class GitStat

Public Class Methods

new(git) click to toggle source
# File lib/git_heat/git_stat.rb, line 4
def initialize(git)
  @git = git
end

Public Instance Methods

stats() click to toggle source
# File lib/git_heat/git_stat.rb, line 8
def stats
  commits = []
  @git.stat_history.each_line do |line|
    if line =~ /^commit:/
      commits << {}
      commits.last[:commit] = line[/^commit: (.*?) /, 1]
      commits.last[:time] = Time.parse(line[/^commit: .*? (.*)/, 1])
    elsif line =~ /^\d/
      commits.last[:affected_files] ||= []
      commits.last[:affected_files] << {}
      commits.last[:affected_files].last[:file] = line[/^\d+\s\d+\s(.*)$/, 1]
      insertions = line[/^(\d+)/, 1]
      deletions = line[/^(\d+) (\d+)/, 2]
      commits.last[:affected_files].last[:insertions] = insertions.to_i
      commits.last[:affected_files].last[:deletions] = deletions.to_i
    end
  end
  commits
end