Class: SourceNotes::Extractor::Annotation

Inherits:
Struct
  • Object
show all
Defined in:
lib/source_notes.rb

Overview

Annotation objects are triplets :line, :tag, :text that represent the line where the annotation lives, its tag, and its text. Note the filename is not stored.

Annotations are looked for in comments and modulus whitespace they have to start with the tag optionally followed by a colon. Everything up to the end of the line (or closing ERB comment tag) is considered to be their text.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



12
13
14
# File 'lib/source_notes.rb', line 12

def line
  @line
end

#tagObject

Returns the value of attribute tag

Returns:

  • (Object)

    the current value of tag



12
13
14
# File 'lib/source_notes.rb', line 12

def tag
  @tag
end

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



12
13
14
# File 'lib/source_notes.rb', line 12

def text
  @text
end

Instance Method Details

#to_s(options = {}) ⇒ Object

Returns a representation of the annotation that looks like this:

[126] [TODO] This algorithm is simple and clearly correct, make it faster.

If options has a flag :tag the tag is shown as in the example above. Otherwise the string contains just line and text.



19
20
21
22
23
# File 'lib/source_notes.rb', line 19

def to_s(options={})
  s = "[#{line.to_s.rjust(options[:indent])}] "
  s << "[#{tag}] " if options[:tag]
  s << text
end