Class: CodeHunter::GitBlamer

Inherits:
Object
  • Object
show all
Defined in:
lib/code_hunter/git_blamer.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ GitBlamer

Returns a new instance of GitBlamer.



3
4
5
6
# File 'lib/code_hunter/git_blamer.rb', line 3

def initialize(args)
  @path = args[:path]
  @line = args[:line]
end

Instance Method Details

#blameObject



8
9
10
11
# File 'lib/code_hunter/git_blamer.rb', line 8

def blame
  result = invoke
  parse(result) unless result.empty?
end

#invokeObject



22
23
24
# File 'lib/code_hunter/git_blamer.rb', line 22

def invoke
  `git blame #{File.realpath(@path)} -L #@line,+1 -l -p`
end

#parse(str) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/code_hunter/git_blamer.rb', line 13

def parse(str)
  {
    :sha1        => str.lines.to_a[0][/^[0-9a-f]+/],
    :author      => str[/author (.+)/, 1],
    :email       => str[/author-mail <(.+)>/, 1],
    :modified_at => str[/author-time (\d+)/, 1].to_i,
  }
end