class Evertils::Helper::ApiEnmlHandler
Public Class Methods
new(conf)
click to toggle source
@since 0.3.7
# File lib/evertils/helpers/api-enml-handler.rb, line 8 def initialize(conf) @config = conf self end
Public Instance Methods
clear_empty()
click to toggle source
@since 0.3.15
# File lib/evertils/helpers/api-enml-handler.rb, line 45 def clear_empty @xml.css('div').each do |node| children = node.children if children.size == 1 && children.first.is_a?(Nokogiri::XML::Text) node.remove if node.text.strip.empty? end end @xml end
convert_to_xml(enml)
click to toggle source
@since 0.3.7
# File lib/evertils/helpers/api-enml-handler.rb, line 27 def convert_to_xml(enml) @xml = from_str(enml) self end
Also aliased as: to_xml
fix_dtd()
click to toggle source
Sometimes, the Doctype declaration gets borked by the XML parser lets replace it with a new DTD
if that is the case @since 0.3.15
# File lib/evertils/helpers/api-enml-handler.rb, line 60 def fix_dtd node = @xml.children[0] # the node we are looking at is actually the XML node, skip it if node.is_a?(ProcessingInstruction) node = node.next end # remove the existing broken DTD node.remove # create a new one (note: output is overridden in DTD class defined # below ApiEnmlHandler) dtd = DTD.new('DOCTYPE', @xml) @xml.children.first.before(dtd) end
from_str(str)
click to toggle source
@since 0.3.13
# File lib/evertils/helpers/api-enml-handler.rb, line 15 def from_str(str) str.sub!("\n", '') @xml = DocumentFragment.parse(str) do |conf| conf.noblanks end fix_dtd clear_empty end
prepare()
click to toggle source
@since 0.3.5
# File lib/evertils/helpers/api-enml-handler.rb, line 35 def prepare note_xml = @xml.search('en-note') # remove <br> tags note_xml.search('br').each(&:remove) note_xml.inner_html.to_s end
to_enml(hash)
click to toggle source
@since 0.3.1
# File lib/evertils/helpers/api-enml-handler.rb, line 79 def to_enml(hash) Evertils::Helper::EvernoteENML.with_list(hash) end