class Evertils::Common::Converter::YamlToEnml
Public Instance Methods
from_file(path)
click to toggle source
@since 0.2.9
# File lib/evertils/common/converter/yaml_to_enml.rb, line 8 def from_file(path) contents = File.open(path, "rb") { |io| io.read } obj = YAML::load(contents) builder(obj) end
from_string(yaml)
click to toggle source
@since 0.2.9
# File lib/evertils/common/converter/yaml_to_enml.rb, line 17 def from_string(yaml) obj = YAML::load(yaml) builder(obj) end
Private Instance Methods
builder(obj)
click to toggle source
@since 0.2.9
# File lib/evertils/common/converter/yaml_to_enml.rb, line 27 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