class Doing::Note
This class describes an item note.
Public Class Methods
Source
# File lib/doing/note.rb, line 14 def initialize(note = []) super() add(note) if note end
Initializes a new note
@param note [Array] Initial note, can be string or array
Public Instance Methods
Source
# File lib/doing/note.rb, line 28 def add(note, replace: false) clear if replace case note when String append_string(note) when Array append(note) end end
Add note contents, optionally replacing existing note
@param note [Array|String|Note] The note to add, can be String
, Array
, or Note
@param replace [Boolean] replace existing content
Source
# File lib/doing/note.rb, line 43 def compress delete_if { |l| l =~ /^\s*$/ || l =~ /^#/ } end
Remove blank lines and comments (#)
@return [Array] compressed array
Source
# File lib/doing/note.rb, line 99 def equal?(other) return false unless other.is_a?(Note) to_s == other.to_s end
Test if a note is equal (compare string representations)
@param other [Note] The other Note
@return [Boolean] true if equal
Source
# File lib/doing/note.rb, line 88 def inspect "<Doing::Note - characters:#{compress.strip_lines.join(' ').length} lines:#{count}>" end
@private
Source
# File lib/doing/note.rb, line 57 def strip_lines Note.new(map(&:strip)) end
Remove leading/trailing whitespace for every line of note
@return [Array] Stripped note
Source
# File lib/doing/note.rb, line 83 def to_line(separator: ' ') compress.strip_lines.join(separator) end
Returns note as a single line, newlines separated by space
@return [String] Line representation of the Note
.
@param separator The separator with which to join multiple lines
Source
# File lib/doing/note.rb, line 70 def to_s(prefix: "\t\t") compress.strip_lines.map { |l| "#{prefix}#{l}" }.join("\n") end
Note
as multi-line string
@param prefix [String] prefix for each line (default two tabs, TaskPaper format)
Private Instance Methods
Source
# File lib/doing/note.rb, line 112 def append(lines) concat(lines.utf8) replace compress end
Append an array of strings to note
@param lines [Array] Array
of strings
Source
# File lib/doing/note.rb, line 123 def append_string(input) concat(input.utf8.split(/\n/).map(&:strip)) replace compress end
Append a string to the note content
@param input [String] The input string, newlines will be split