class JEDICT::Parser::Entry

Attributes

callback[RW]
parents[RW]
position[RW]

Public Class Methods

new(prc) click to toggle source
# File lib/jedict.rb, line 143
def initialize prc
  @callback = prc
  @parents = []
  @position = {} 
end

Public Instance Methods

characters(string) click to toggle source
# File lib/jedict.rb, line 166
def characters(string)
  string.gsub!(/[\n]/, "")
  string.strip!
  position[:value] = string unless string == ""
end
end_element(name) click to toggle source
# File lib/jedict.rb, line 172
def end_element(name)
  self.position = parents.pop
  if name == "entry"
    position[:entry].extend NodeExtention
    callback.call(position[:entry])
    self.position = {}
    self.parents = []
  end
end
start_element(name, attrs) click to toggle source
# File lib/jedict.rb, line 149
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() click to toggle source
# File lib/jedict.rb, line 182
def value
  nil
end