class Mercurial::Blame

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

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

Constants

METADATA_AND_CODE_RE
METADATA_RE

Attributes

contents[R]
repository[R]

Public Class Methods

new(repository, data) click to toggle source
# File lib/mercurial-ruby/blame.rb, line 18
def initialize(repository, data)
  @repository = repository
  @contents = data
end

Public Instance Methods

contents_without_metadata() click to toggle source

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

# File lib/mercurial-ruby/blame.rb, line 27
def contents_without_metadata
  contents.gsub(METADATA_RE, '')
end
lines() click to toggle source

Returns an array of {Mercurial::BlameLine BlameLine} instances.

# 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_metadata() click to toggle source

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

# File lib/mercurial-ruby/blame.rb, line 35
def raw_metadata
  contents.scan(METADATA_RE)
end