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

Version Path
evertils-common-0.3.18 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.17 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.16 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.15 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.14 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.13 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.12 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.11 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.10 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.9 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.8 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.7 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.6 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.5 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.4.1 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.4 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.4.1.pre.dev lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.3.1 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.3 lib/evertils/common/converter/yaml_to_enml.rb
evertils-common-0.3.2 lib/evertils/common/converter/yaml_to_enml.rb