class Doing::Note

This class describes an item note.

Public Class Methods

new(note = []) click to toggle source

Initializes a new note

@param note [Array] Initial note, can be string or array

Calls superclass method
# File lib/doing/note.rb, line 14
def initialize(note = [])
  super()

  add(note) if note
end

Public Instance Methods

add(note, replace: false) click to toggle source

Add note contents, optionally replacing existing note

@param note [Array] The note to add, can be String, Array, or Note @param replace [Boolean] replace existing content

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

Remove blank lines and comments (#)

@return [Array] compressed array

# File lib/doing/note.rb, line 43
def compress
  delete_if { |l| l =~ /^\s*$/ || l =~ /^#/ }
end
compress!() click to toggle source
# File lib/doing/note.rb, line 47
def compress!
  replace compress
end
equal?(other) click to toggle source

Test if a note is equal (compare string representations)

@param other [Note] The other Note

@return [Boolean] true if equal

# File lib/doing/note.rb, line 99
def equal?(other)
  return false unless other.is_a?(Note)

  to_s == other.to_s
end
inspect() click to toggle source

@private

# File lib/doing/note.rb, line 88
def inspect
  "<Doing::Note - characters:#{compress.strip_lines.join(' ').length} lines:#{count}>"
end
strip_lines() click to toggle source

Remove leading/trailing whitespace for every line of note

@return [Array] Stripped note

# File lib/doing/note.rb, line 57
def strip_lines
  Note.new(map(&:strip))
end
strip_lines!() click to toggle source
# File lib/doing/note.rb, line 61
def strip_lines!
  replace strip_lines
end
to_line(separator: ' ') click to toggle source

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

# File lib/doing/note.rb, line 83
def to_line(separator: ' ')
  compress.strip_lines.join(separator)
end
to_s(prefix: "\t\t") click to toggle source

Note as multi-line string

@param prefix [String] prefix for each line (default two tabs, TaskPaper format)

# File lib/doing/note.rb, line 70
def to_s(prefix: "\t\t")
  compress.strip_lines.map { |l| "#{prefix}#{l}" }.join("\n")
end

Private Instance Methods

append(lines) click to toggle source

Append an array of strings to note

@param lines [Array] Array of strings

# File lib/doing/note.rb, line 112
def append(lines)
  concat(lines.utf8)
  replace compress
end
append_string(input) click to toggle source

Append a string to the note content

@param input [String] The input string, newlines will be split

# File lib/doing/note.rb, line 123
def append_string(input)
  concat(input.utf8.split(/\n/).map(&:strip))
  replace compress
end