Sha256: cda3e75e2adb12fc63c8abb0fe7ffc3e943a516d981ae9f571497411193438d4
Contents?: true
Size: 1.16 KB
Versions: 23
Compression:
Stored size: 1.16 KB
Contents
module Evertils module Common module Converter class YamlToEnml < Converter::Base # # @since 0.2.9 def from_file(path) contents = File.open(path, "rb") { |io| io.read } obj = YAML::load(contents) builder(obj) end # # @since 0.2.9 def from_string(yaml) obj = YAML::load(yaml) builder(obj) end private # # @since 0.2.9 def builder(obj) # hardcoding XML here because it's quick/easy enml = '<?xml version="1.0" encoding="UTF-8"?>' enml += '<!DOCTYPE "en-note" SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' enml += '<en-note>' obj.each do |k, v| if v.is_a? Array enml += "<p>#{k}</p>" enml += "<ul>" v.each do |child| enml += "<li>#{child}</li>" end enml += "</ul>" else enml += "<p>#{k}: #{v}</p>" end end enml += '</en-note>' enml end end end end end
Version data entries
23 entries across 23 versions & 1 rubygems