class DNote::Note
The Note
class encapsulates a single note made in a source file.
Each note instance holds a reference, notes
, to the set of notes being generated for a given session. This allows the note to access general options applicable to all notes.
Attributes
Contextual lines of code.
The file in which the note is made.
The type of note.
The line number of the note.
Remark marker used in parsing the note.
Set of notes to which this note belongs.
The verbatim text of the note.
Public Class Methods
Initialize new Note
instance.
# File lib/dnote/note.rb, line 32 def initialize(notes, file, label, line, text, mark) @notes = notes @file = file @label = label @line = line @text = text.rstrip @mark = mark @capture = [] end
Public Instance Methods
Sort by file name and line number.
# File lib/dnote/note.rb, line 58 def <=>(other) s = file <=> other.file return s unless s == 0 line <=> other.line end
# File lib/dnote/note.rb, line 101 def code unindent(capture).join end
Is there code to show?
# File lib/dnote/note.rb, line 106 def code? !capture.empty? end
Remove newlines from note text.
# File lib/dnote/note.rb, line 53 def textline text.tr("\n", " ") end
Convert to Hash.
# File lib/dnote/note.rb, line 70 def to_h {"label" => label, "text" => textline, "file" => file, "line" => line} end
Convert to Hash, leaving the note text verbatim.
# File lib/dnote/note.rb, line 75 def to_h_raw {"label" => label, "text" => text, "file" => file, "line" => line, "code" => code} end
Convert to JSON.
# File lib/dnote/note.rb, line 80 def to_json(*args) to_h_raw.to_json(*args) end
Convert to string representation.
# File lib/dnote/note.rb, line 43 def to_s "#{label}: #{text}" end
Convert to string representation.
# File lib/dnote/note.rb, line 48 def to_str "#{label}: #{text}" end
Convert to YAML.
# File lib/dnote/note.rb, line 85 def to_yaml(*args) to_h_raw.to_yaml(*args) end
Return line URL based on URL template. If no template was set, then returns the file.
FIXME: Move out of Note
so we can drop the reference to notes
# File lib/dnote/note.rb, line 93 def url if notes.url format(notes.url, file, line) else file end end
Private Instance Methods
Remove blank space from lines.
# File lib/dnote/note.rb, line 113 def unindent(lines) dents = [] lines.each do |line| if (md = /^(\ *)/.match(line)) dents << md[1] end end dent = dents.min_by(&:size) lines.map do |line| line.sub(dent, "") end end