Class: JEDICT::Parser::Entry
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- JEDICT::Parser::Entry
- Defined in:
- lib/jedict.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#parents ⇒ Object
Returns the value of attribute parents.
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
- #characters(string) ⇒ Object
- #end_element(name) ⇒ Object
-
#initialize(prc) ⇒ Entry
constructor
A new instance of Entry.
- #start_element(name, attrs) ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(prc) ⇒ Entry
90 91 92 93 94 |
# File 'lib/jedict.rb', line 90 def initialize prc @callback = prc @parents = [] @position = {} end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
88 89 90 |
# File 'lib/jedict.rb', line 88 def callback @callback end |
#parents ⇒ Object
Returns the value of attribute parents.
88 89 90 |
# File 'lib/jedict.rb', line 88 def parents @parents end |
#position ⇒ Object
Returns the value of attribute position.
88 89 90 |
# File 'lib/jedict.rb', line 88 def position @position end |
Instance Method Details
#characters(string) ⇒ Object
113 114 115 116 117 |
# File 'lib/jedict.rb', line 113 def characters(string) string.gsub!(/[\n]/, "") string.strip! position[:value] = string unless string == "" end |
#end_element(name) ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/jedict.rb', line 119 def end_element(name) self.position = parents.pop if name == "entry" position[:entry].extend NodePrinting callback.call(position[:entry]) self.position = {} self.parents = [] end end |
#start_element(name, attrs) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/jedict.rb', line 96 def start_element(name, attrs) return if name == "JMdict" name = name.to_sym pos = position[name] if !pos self.position[name] = {} elsif pos.is_a? Array position[name] << {} else self.position[name] = [pos, {}] end self.parents << position self.position = position[name] self.position = position[-1] if position.is_a? Array self.position[:attrs] = attrs.flatten if attrs.flatten.length > 0 end |
#value ⇒ Object
129 130 131 |
# File 'lib/jedict.rb', line 129 def value nil end |