class Eiwa::Jmdict::Doc
Public Class Methods
new(each_entry_block)
click to toggle source
# File lib/eiwa/jmdict/doc.rb, line 23 def initialize(each_entry_block) @each_entry_block = each_entry_block @current = nil end
Public Instance Methods
characters(s)
click to toggle source
# File lib/eiwa/jmdict/doc.rb, line 52 def characters(s) @current.add_characters(s) end
end_document()
click to toggle source
# File lib/eiwa/jmdict/doc.rb, line 31 def end_document end
end_element(name)
click to toggle source
# File lib/eiwa/jmdict/doc.rb, line 40 def end_element(name) raise Eiwa::Error.new("Parsing error. Expected <#{@current.tag_name}> to close before <#{name}>") if @current.tag_name != name ending = @current ending.end_self if ending.is_a?(Tag::Entry) @each_entry_block&.call(ending) end @current = ending.parent @current&.end_child(ending) end
error(msg)
click to toggle source
def warning string
puts "warning #{string}"
end
# File lib/eiwa/jmdict/doc.rb, line 64 def error(msg) if (matches = msg.match(/Entity '(\S+)' not defined/)) # See: http://github.com/sparklemotion/nokogiri/issues/1926 code = matches[1] @current.set_entity(code, ENTITIES[code]) elsif msg == "Detected an entity reference loop\n" # Do nothing and hope this does not matter. else raise Eiwa::Error.new("Parsing error: #{msg}") end end
start_document()
click to toggle source
# File lib/eiwa/jmdict/doc.rb, line 28 def start_document end
start_element(name, attrs)
click to toggle source
# File lib/eiwa/jmdict/doc.rb, line 34 def start_element(name, attrs) parent = @current @current = (TAGS[name] || Tag::Other).new @current.start(name, attrs, parent) end