Class: GitStat

Inherits:
Object
  • Object
show all
Defined in:
lib/git_heat/git_stat.rb

Instance Method Summary collapse

Constructor Details

#initialize(git) ⇒ GitStat

Returns a new instance of GitStat.



4
5
6
# File 'lib/git_heat/git_stat.rb', line 4

def initialize(git)
  @git = git
end

Instance Method Details

#statsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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