Module: Synclenote::NoteBuilder

Defined in:
lib/synclenote/note_builder.rb

Constant Summary collapse

DEFAULT_TAGS =
%w[syncle]
TITLE_IF_EMPTY =
"no title"

Class Method Summary collapse

Class Method Details

.call(raw_note, guid: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/synclenote/note_builder.rb', line 7

def call(raw_note, guid: nil)
  lines = raw_note.each_line.lazy
  title, tags_in_raw_note, body_markdown = *parse_lines(lines)
  title = TITLE_IF_EMPTY if /\A\s*\z/ === title
  tags = (DEFAULT_TAGS + tags_in_raw_note).uniq
  enml = Synclenote::MarkdownToEnmlBuilder.(body_markdown)

  options = {
    title:,
    content: enml,
    tagNames: tags,
  }
  options[:guid] = guid if guid
  return Evernote::EDAM::Type::Note.new(options)
end