Sha256: 64ebd8b853f287a2f214daa8e72a0dfb3ecc8bc72f32b0728950437842193e9e

Contents?: true

Size: 1.57 KB

Versions: 59

Compression:

Stored size: 1.57 KB

Contents

module Evertils
  module Helper
    class EvernoteENML
      attr_reader :element, :embeddable_element

      # TODO: refactor this whole class so you can create ENML elements with it
      def initialize(file = nil)
        @file = file
        @element = enml_element

        if !@element.nil?
          @embeddable_element = "<hr/>Attachment with hash #{@element.data.bodyHash}<br /><en-media type=\"#{@element.mime}\" hash=\"#{@element.data.bodyHash}\" /><br /><br />"
        end
      end

      def self.with_list(arr)
        enml_bucket = []

        if arr.respond_to? :each_pair
          arr.each_pair do |title, data|
            enml_bucket.push("<br /><div><span style=\"font-size: 18px;\">#{title}</span></div>")

            enml_bucket.push('<ul>')

            data.each do |item|
              enml_bucket.push("<li>#{item}</li>")
            end

            enml_bucket.push('</ul>')
          end

          enml_bucket.join
        end
      end

      private

      def enml_element
        if @file
          read_file = File.open(@file, 'rb') { |io| io.read }

          el = ::Evernote::EDAM::Type::Resource.new()
          el.mime = MIME::Types.type_for(@file)[0].content_type
          el.data = ::Evernote::EDAM::Type::Data.new()
          el.data.size = read_file.size
          el.data.bodyHash = Digest::MD5.hexdigest(read_file)
          el.data.body = read_file
          el.attributes = ::Evernote::EDAM::Type::ResourceAttributes.new()
          el.attributes.fileName = @file # temporary for now, the actual file name
          el
        end
      end

    end
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
evertils-0.3.15 lib/evertils/helpers/evernote-enml.rb
evertils-0.3.14.1 lib/evertils/helpers/evernote-enml.rb
evertils-0.3.14 lib/evertils/helpers/evernote-enml.rb
evertils-0.3.13 lib/evertils/helpers/evernote-enml.rb
evertils-0.3.12 lib/evertils/helpers/evernote-enml.rb
evertils-0.3.11 lib/evertils/helpers/evernote-enml.rb
evertils-0.3.10 lib/evertils/helpers/evernote-enml.rb
evertils-0.3.9 lib/evertils/helpers/evernote-enml.rb
evertils-0.3.8 lib/evertils/helpers/evernote-enml.rb
evertils-0.3.7 lib/helpers/evernote-enml.rb
evertils-0.3.6 lib/helpers/evernote-enml.rb
evertils-0.3.5 lib/helpers/evernote-enml.rb
evertils-0.3.4 lib/helpers/evernote-enml.rb
evertils-0.3.3 lib/helpers/evernote-enml.rb
evertils-0.3.2 lib/helpers/evernote-enml.rb
evertils-0.3.1.3 lib/helpers/evernote-enml.rb
evertils-0.3.1.2 lib/helpers/evernote-enml.rb
evertils-0.3.1.1 lib/helpers/evernote-enml.rb
evertils-0.3.1 lib/helpers/evernote-enml.rb