Class: GitStatistics::CommitLineExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/git_statistics/commit_line_extractor.rb

Constant Summary collapse

AdditionsOrDeletions =
RegexMatcher.new(/^([-|\d]+)\s+([-|\d]+)\s+(.+)/i, 3)
RenamedOrCopied =
RegexMatcher.new(/^(rename|copy)\s+(.+)\s+=>\s+(.+)\s+\((\d+)/i, 4)
CreatedOrDeleted =
RegexMatcher.new(/^(create|delete) mode \d+ ([^\\\n]*)/i, 2)
ModifiedOrRenamed =
RegexMatcher.new(/^([-|\d]+)\s+([-|\d]+)\s+(.+)\s+=>\s+(.+)/i, 4)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ CommitLineExtractor

Returns a new instance of CommitLineExtractor.



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

def initialize(line)
  @line = line
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



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

def line
  @line
end

Instance Method Details

#changedObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/git_statistics/commit_line_extractor.rb', line 15

def changed
  modified_or_renamed = ModifiedOrRenamed.if_matches(line) do |changes|
    split_file = Utilities.split_old_new_file(changes[2], changes[3])
    {:additions => changes[0].to_i,
      :deletions => changes[1].to_i,
      :file => split_file[:new_file],
      :old_file => split_file[:old_file]}
  end
  return modified_or_renamed unless modified_or_renamed.empty?

  AdditionsOrDeletions.if_matches(line) do |changes|
    {:additions => changes[0].to_i,
      :deletions => changes[1].to_i,
      :file => changes[2]}
  end
end

#created_or_deletedObject



32
33
34
35
36
37
# File 'lib/git_statistics/commit_line_extractor.rb', line 32

def created_or_deleted
  CreatedOrDeleted.if_matches(line) do |changes|
    {:status => changes[0],
      :file => changes[1]}
  end
end

#renamed_or_copiedObject



39
40
41
42
43
44
45
46
47
# File 'lib/git_statistics/commit_line_extractor.rb', line 39

def renamed_or_copied
  RenamedOrCopied.if_matches(line) do |changes|
    split_file = Utilities.split_old_new_file(changes[1], changes[2])
    {:status => changes[0],
      :old_file => split_file[:old_file],
      :new_file => split_file[:new_file],
      :similar => changes[3].to_i}
  end
end