Class: CommitAccumulator

Inherits:
Object
  • Object
show all
Defined in:
lib/gitstats/stats/commit.rb

Direct Known Subclasses

CommitStats

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommitAccumulator

Returns a new instance of CommitAccumulator.



18
19
20
21
22
23
24
25
26
# File 'lib/gitstats/stats/commit.rb', line 18

def initialize
  @commits = 0
  @files_added = 0
  @files_deleted = 0
  @lines_added = 0
  @lines_deleted = 0
  @first_commit = nil
  @last_commit = nil
end

Instance Attribute Details

#commitsObject (readonly)

Returns the value of attribute commits.



2
3
4
# File 'lib/gitstats/stats/commit.rb', line 2

def commits
  @commits
end

#files_addedObject (readonly)

Returns the value of attribute files_added.



3
4
5
# File 'lib/gitstats/stats/commit.rb', line 3

def files_added
  @files_added
end

#files_deletedObject (readonly)

Returns the value of attribute files_deleted.



4
5
6
# File 'lib/gitstats/stats/commit.rb', line 4

def files_deleted
  @files_deleted
end

#first_commitObject (readonly)

Returns the value of attribute first_commit.



7
8
9
# File 'lib/gitstats/stats/commit.rb', line 7

def first_commit
  @first_commit
end

#last_commitObject (readonly)

Returns the value of attribute last_commit.



8
9
10
# File 'lib/gitstats/stats/commit.rb', line 8

def last_commit
  @last_commit
end

#lines_addedObject (readonly)

Returns the value of attribute lines_added.



5
6
7
# File 'lib/gitstats/stats/commit.rb', line 5

def lines_added
  @lines_added
end

#lines_deletedObject (readonly)

Returns the value of attribute lines_deleted.



6
7
8
# File 'lib/gitstats/stats/commit.rb', line 6

def lines_deleted
  @lines_deleted
end

Instance Method Details

#filesObject



10
11
12
# File 'lib/gitstats/stats/commit.rb', line 10

def files
  @files_added - @files_deleted
end

#linesObject



14
15
16
# File 'lib/gitstats/stats/commit.rb', line 14

def lines
  @lines_added - @lines_deleted
end

#update(commit) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gitstats/stats/commit.rb', line 28

def update(commit)
  @commits += 1
  @files_added += commit[:files_added]
  @files_deleted += commit[:files_deleted]
  @lines_added += commit[:lines_added]
  @lines_deleted += commit[:lines_deleted]

  @first_commit ||= commit[:time]
  @last_commit ||= commit[:time]

  @first_commit = commit[:time] if commit[:time] < @first_commit
  @last_commit = commit[:time] if commit[:time] > @last_commit
end