Class: Mercurial::Blame

Inherits:
Object
  • Object
show all
Defined in:
lib/mercurial-ruby/blame.rb

Overview

The class represents Mercurial blame output (+hg blame+ command).

This class is for Blame object itself, BlameFactory is responsible for assembling instances of Blame. For the list of all possible blame-related operations check BlameFactory.

Constant Summary collapse

METADATA_RE =
/^(.+) (\w{12}): *(\d+): /
METADATA_AND_CODE_RE =
/^(.+) (\w{12}): *(\d+): (.*)$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, data) ⇒ Blame

Returns a new instance of Blame.



18
19
20
21
# File 'lib/mercurial-ruby/blame.rb', line 18

def initialize(repository, data)
  @repository = repository
  @contents = data
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



16
17
18
# File 'lib/mercurial-ruby/blame.rb', line 16

def contents
  @contents
end

#repositoryObject (readonly)

Returns the value of attribute repository.



15
16
17
# File 'lib/mercurial-ruby/blame.rb', line 15

def repository
  @repository
end

Instance Method Details

#contents_without_metadataObject

Returns code only as a String without the usual blame metadata. Useful for code highlighting.



27
28
29
# File 'lib/mercurial-ruby/blame.rb', line 27

def 
  contents.gsub(METADATA_RE, '')
end

#linesObject

Returns an array of BlameLine instances.



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mercurial-ruby/blame.rb', line 42

def lines
  [].tap do |result|
    contents.each_line do |line|
      author, revision, linenum, text = line.scan(METADATA_AND_CODE_RE).first
      result << BlameLine.new(
        :author   => author,
        :revision => revision,
        :num      => linenum,
        :contents => text
      )
    end
  end
end

#raw_metadataObject

Returns an Array of blame metadata for every line of blame. Does not return code itself.



35
36
37
# File 'lib/mercurial-ruby/blame.rb', line 35

def 
  contents.scan(METADATA_RE)
end