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
# 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
end

Instance Attribute Details

#commitsObject (readonly)

Returns the value of attribute commits.



38
39
40
# File 'lib/git/heatmap/commits.rb', line 38

def commits
  @commits
end

#earliest_commit_atObject (readonly)

Returns the value of attribute earliest_commit_at.



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

def earliest_commit_at
  @earliest_commit_at
end

#latest_commit_atObject (readonly)

Returns the value of attribute latest_commit_at.



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

def latest_commit_at
  @latest_commit_at
end

#maximumObject (readonly)

Returns the value of attribute maximum.



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

def maximum
  @maximum
end

#periodsObject (readonly)

Returns the value of attribute periods.



39
40
41
# File 'lib/git/heatmap/commits.rb', line 39

def periods
  @periods
end

Instance Method Details

#<<(commit) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/git/heatmap/commits.rb', line 50

def << commit
  return if @commits.include?(commit.oid)
  
  @commits[commit.oid] = commit
  
  author = commit.author
  time = author[:time]
  key = @filter.key(time)
  commits = (@periods[key] ||= [])
  commits << commit
  
  if commits.size > @maximum
    @maximum = commits.size
  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



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

def size
  @commits.size
end