Class: Ever2boost::EnexConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/ever2boost/enex_converter.rb

Class Method Summary collapse

Class Method Details

.convert(enex, output_dir, filename) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ever2boost/enex_converter.rb', line 7

def convert(enex, output_dir, filename)
  puts 'converting...'
  en_notes = parse_plural_notes(enex, output_dir)
  notebook_list = [NoteList.new(title: filename)]
  JsonGenerator.output(notebook_list, output_dir)
  en_notes.each do |note|
    puts "converting #{note.title}"
    CsonGenerator.output(notebook_list.first.hash, note, output_dir)
  end
  puts Util.green_output("The notes are created at #{output_dir}")
end

.parse_plural_notes(enex, output_dir) ⇒ Object

enex: String

"<?xml>(.*)</en-export>"

return: Array

include Note objects
note.content = "<note>(.*)</note>"

comment:

A .enex file include plural ntoes. Thus I need to handle separation into each note.


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ever2boost/enex_converter.rb', line 26

def parse_plural_notes(enex, output_dir)
  REXML::Document.new(enex).elements['en-export'].map do |el|
    if el != "\n"
      xml_document = REXML::Document.new(el.to_s).elements
      Note.new({
        title: xml_document['note/title'].text,
        content: "<div>#{xml_document['note/content/text()'].to_s.sub(/<\?xml(.*?)\?>(.*?)<\!DOCTYPE(.*?)>/m, '')}</div>",
        output_dir: output_dir
      })
    end
  end.compact.flatten
end