Class: Git::Heatmap::Aggregate

Inherits:
Object
  • Object
show all
Defined in:
lib/git/heatmap/commits.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter) ⇒ Aggregate

Returns a new instance of Aggregate.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/git/heatmap/commits.rb', line 26

def initialize(filter)
	@filter = filter
	
	@commits = {}
	
	@periods = {}
	@earliest_commit_at = nil
	@latest_commit_at = nil
	
	@maximum = 0
	
	@additions = Hash.new{|h,k| h[k] = 0}
	@deletions = Hash.new{|h,k| h[k] = 0}
	@churn = Hash.new{|h,k| h[k] = 0}
end

Instance Attribute Details

#additionsObject (readonly)

Returns the value of attribute additions.



48
49
50
# File 'lib/git/heatmap/commits.rb', line 48

def additions
  @additions
end

#churnObject (readonly)

Returns the value of attribute churn.



50
51
52
# File 'lib/git/heatmap/commits.rb', line 50

def churn
  @churn
end

#commitsObject (readonly)

Returns the value of attribute commits.



42
43
44
# File 'lib/git/heatmap/commits.rb', line 42

def commits
  @commits
end

#deletionsObject (readonly)

Returns the value of attribute deletions.



49
50
51
# File 'lib/git/heatmap/commits.rb', line 49

def deletions
  @deletions
end

#earliest_commit_atObject (readonly)

Returns the value of attribute earliest_commit_at.



45
46
47
# File 'lib/git/heatmap/commits.rb', line 45

def earliest_commit_at
  @earliest_commit_at
end

#latest_commit_atObject (readonly)

Returns the value of attribute latest_commit_at.



46
47
48
# File 'lib/git/heatmap/commits.rb', line 46

def latest_commit_at
  @latest_commit_at
end

#maximumObject (readonly)

Returns the value of attribute maximum.



56
57
58
# File 'lib/git/heatmap/commits.rb', line 56

def maximum
  @maximum
end

#periodsObject (readonly)

Returns the value of attribute periods.



43
44
45
# File 'lib/git/heatmap/commits.rb', line 43

def periods
  @periods
end

Instance Method Details

#add(commit, patch) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/git/heatmap/commits.rb', line 58

def add(commit, patch)
	author = commit.author
	time = author[:time]
	key = @filter.key(time)
	
	unless @commits.include?(commit.oid)
		@commits[commit.oid] = commit
		
		commits = (@periods[key] ||= [])
		commits << commit
	end
	
	@additions[key] += patch.additions
	@deletions[key] += patch.deletions
	
	churn = patch.additions + patch.deletions.abs
	@churn[key] += churn
	
	total_churn = @churn[key]
	
	if total_churn > @maximum
		@maximum = total_churn
	end
	
	if @earliest_commit_at.nil? or time < @earliest_commit_at
		@earliest_commit_at = time
	end
	
	if @latest_commit_at.nil? or time > @latest_commit_at
		@latest_commit_at = time
	end
end

#sizeObject



52
53
54
# File 'lib/git/heatmap/commits.rb', line 52

def size
	@commits.size
end