Class: Eiwa::Jmdict::Doc

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/eiwa/jmdict/doc.rb

Instance Method Summary collapse

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_documentObject



31
32
# File 'lib/eiwa/jmdict/doc.rb', line 31

def end_document
end

#end_element(name) ⇒ Object

Raises:



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

Raises:



68
69
70
# File 'lib/eiwa/jmdict/doc.rb', line 68

def error(msg)
  raise Eiwa::Error.new("Parsing error: #{msg}")
end

#reference(name, content) ⇒ Object



56
57
58
# File 'lib/eiwa/jmdict/doc.rb', line 56

def reference(name, content)
  @current.set_entity(name, content)
end

#start_documentObject



28
29
# File 'lib/eiwa/jmdict/doc.rb', line 28

def start_document
end

#start_element(name, attrs) ⇒ Object



34
35
36
37
38
# 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