Method: NA::Editor.format_input
- Defined in:
- lib/na/editor.rb
.format_input(input) ⇒ Array
Takes a multi-line string and formats it as an entry
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/na/editor.rb', line 115 def format_input(input) NA.notify("#{NA.theme[:error]}No content in entry", exit_code: 1) if input.nil? || input.strip.empty? input_lines = input.split(/[\n\r]+/).delete_if(&:ignore?) title = input_lines[0]&.strip NA.notify("#{NA.theme[:error]}No content in first line", exit_code: 1) if title.nil? || title.strip.empty? title = title. note = if input_lines.length > 1 input_lines[1..] else [] end unless note.empty? note.map!(&:strip) note.delete_if { |l| l =~ /^\s*$/ || l =~ /^#/ } end [title, note] end |