Class: Eiwa::Jmdict::Doc
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Eiwa::Jmdict::Doc
- Defined in:
- lib/eiwa/jmdict/doc.rb
Instance Method Summary collapse
- #characters(s) ⇒ Object
- #end_document ⇒ Object
- #end_element(name) ⇒ Object
-
#error(msg) ⇒ Object
def warning string puts “warning #string” end.
-
#initialize(each_entry_block) ⇒ Doc
constructor
A new instance of Doc.
- #start_document ⇒ Object
- #start_element(name, attrs) ⇒ Object
Constructor Details
#initialize(each_entry_block) ⇒ Doc
Returns a new instance of Doc.
23 24 25 26 |
# File 'lib/eiwa/jmdict/doc.rb', line 23 def initialize(each_entry_block) @each_entry_block = each_entry_block @current = nil end |
Instance Method Details
#characters(s) ⇒ Object
52 53 54 |
# File 'lib/eiwa/jmdict/doc.rb', line 52 def characters(s) @current.add_characters(s) end |
#end_document ⇒ Object
31 32 |
# File 'lib/eiwa/jmdict/doc.rb', line 31 def end_document end |
#end_element(name) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# 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) ⇒ Object
def warning string
puts "warning #{string}"
end
64 65 66 67 68 69 70 71 72 73 74 |
# 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 ⇒ Object
28 29 |
# File 'lib/eiwa/jmdict/doc.rb', line 28 def start_document end |