Class: Doing::Note
Overview
This class describes an item note.
Instance Method Summary collapse
-
#add(note, replace: false) ⇒ Object
Add note contents, optionally replacing existing note.
-
#append(lines) ⇒ Object
Append an array of strings to note.
-
#append_string(input) ⇒ Object
Append a string to the note content.
-
#compress ⇒ Array
Remove blank lines and comment lines (#).
- #compress! ⇒ Object
-
#equal?(other) ⇒ Boolean
Test if a note is equal (compare string representations).
-
#initialize(note = []) ⇒ Note
constructor
Initializes a new note.
-
#strip_lines ⇒ Array
Remove leading/trailing whitespace for every line of note.
- #strip_lines! ⇒ Object
-
#to_s ⇒ Object
Note as multi-line string.
Methods inherited from Array
#highlight_tags, #log_tags, #nested_hash, #to_tags, #to_tags!
Constructor Details
#initialize(note = []) ⇒ Note
Initializes a new note
15 16 17 18 19 |
# File 'lib/doing/note.rb', line 15 def initialize(note = []) super() add(note) if note end |
Instance Method Details
#add(note, replace: false) ⇒ Object
Add note contents, optionally replacing existing note
29 30 31 32 33 34 35 36 |
# File 'lib/doing/note.rb', line 29 def add(note, replace: false) clear if replace if note.is_a?(String) append_string(note) elsif note.is_a?(Array) append(note) end end |
#append(lines) ⇒ Object
Append an array of strings to note
43 44 45 46 |
# File 'lib/doing/note.rb', line 43 def append(lines) concat(lines) replace compress end |
#append_string(input) ⇒ Object
Append a string to the note content
54 55 56 57 |
# File 'lib/doing/note.rb', line 54 def append_string(input) concat(input.split(/\n/).map(&:strip)) replace compress end |
#compress ⇒ Array
Remove blank lines and comment lines (#)
68 69 70 |
# File 'lib/doing/note.rb', line 68 def compress delete_if { |l| l =~ /^\s*$/ || l =~ /^#/ } end |
#compress! ⇒ Object
59 60 61 |
# File 'lib/doing/note.rb', line 59 def compress! replace compress end |
#equal?(other) ⇒ Boolean
Test if a note is equal (compare string representations)
105 106 107 108 109 |
# File 'lib/doing/note.rb', line 105 def equal?(other) return false unless other.is_a?(Note) to_s == other.to_s end |
#strip_lines ⇒ Array
Remove leading/trailing whitespace for every line of note
82 83 84 |
# File 'lib/doing/note.rb', line 82 def strip_lines map(&:strip) end |
#strip_lines! ⇒ Object
72 73 74 |
# File 'lib/doing/note.rb', line 72 def strip_lines! replace strip_lines end |
#to_s ⇒ Object
Note as multi-line string
88 89 90 |
# File 'lib/doing/note.rb', line 88 def to_s compress.strip_lines.map { |l| "\t\t#{l}" }.join("\n") end |