Class: Mercurial::Blame
- Inherits:
-
Object
- Object
- Mercurial::Blame
- 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
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
-
#contents_without_metadata ⇒ Object
Returns code only as a String without the usual blame metadata.
-
#initialize(repository, data) ⇒ Blame
constructor
A new instance of Blame.
-
#lines ⇒ Object
Returns an array of BlameLine instances.
-
#raw_metadata ⇒ Object
Returns an Array of blame metadata for every line of blame.
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
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
16 17 18 |
# File 'lib/mercurial-ruby/blame.rb', line 16 def contents @contents end |
#repository ⇒ Object (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_metadata ⇒ Object
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 |
#lines ⇒ Object
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| , revision, linenum, text = line.scan(METADATA_AND_CODE_RE).first result << BlameLine.new( :author => , :revision => revision, :num => linenum, :contents => text ) end end end |
#raw_metadata ⇒ Object
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 |