Class: Commit

Inherits:
Record show all
Defined in:
lib/record.rb

Instance Attribute Summary collapse

Attributes inherited from Record

#author, #date

Instance Method Summary collapse

Constructor Details

#initialize(commit = nil, date = nil) ⇒ Commit

Returns a new instance of Commit.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/record.rb', line 13

def initialize(commit = nil, date = nil)
    @addition = 0
    @date = date
    if commit
        @author = commit.author.email
        @date = commit.committed_date
        @message = commit.message.gsub("\n",' ')
        @sha = commit.id
        @stats = commit.stats
    end
end

Instance Attribute Details

#additionObject

Time calc



9
10
11
# File 'lib/record.rb', line 9

def addition
  @addition
end

#clocked_inObject

Whether it’s been padded by a clock in/out



11
12
13
# File 'lib/record.rb', line 11

def clocked_in
  @clocked_in
end

#clocked_outObject

Whether it’s been padded by a clock in/out



11
12
13
# File 'lib/record.rb', line 11

def clocked_out
  @clocked_out
end

#diffsObject

From Grit::Commit object



7
8
9
# File 'lib/record.rb', line 7

def diffs
  @diffs
end

#estimatedObject

Time calc



9
10
11
# File 'lib/record.rb', line 9

def estimated
  @estimated
end

#messageObject

From Grit::Commit object



7
8
9
# File 'lib/record.rb', line 7

def message
  @message
end

#minutesObject

Time calc



9
10
11
# File 'lib/record.rb', line 9

def minutes
  @minutes
end

#overridenObject

Time calc



9
10
11
# File 'lib/record.rb', line 9

def overriden
  @overriden
end

#shaObject

From Grit::Commit object



7
8
9
# File 'lib/record.rb', line 7

def sha
  @sha
end

#statsObject

From Grit::Commit object



7
8
9
# File 'lib/record.rb', line 7

def stats
  @stats
end

Instance Method Details

#calculate_diffs(my_files, not_my_files) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/record.rb', line 25

def calculate_diffs(my_files, not_my_files)
    return @diffs if @diffs

    plus, minus = 0, 0

    @stats.to_diffstat.each do |diff_stat|
        should_include = (diff_stat.filename =~ my_files)
        should_ignore = not_my_files && (diff_stat.filename =~ not_my_files)
        if should_include && !should_ignore
            plus += diff_stat.additions
            minus += diff_stat.deletions
        end
    end

    # Weight deletions half as much, since they are typically
    # faster to do & also are 1:1 with additions when changing a line
    @diffs = plus+minus/2
end