Class: VORuby::ActiveVotable::VOTableExtractor

Inherits:
LibXmlSaxParserWrapper show all
Defined in:
lib/voruby/active_votable/active_votable.rb

Instance Attribute Summary collapse

Attributes inherited from LibXmlSaxParserWrapper

#filename

Instance Method Summary collapse

Methods inherited from LibXmlSaxParserWrapper

#add_listener, #method_missing

Constructor Details

#initialize(file, actions = {}) ⇒ VOTableExtractor

Returns a new instance of VOTableExtractor.



31
32
33
34
35
36
37
# File 'lib/voruby/active_votable/active_votable.rb', line 31

def initialize(file, actions={})
  super(file)
    
  @actions = actions
    
  register_listeners()
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class VORuby::ActiveVotable::LibXmlSaxParserWrapper

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



29
30
31
# File 'lib/voruby/active_votable/active_votable.rb', line 29

def actions
  @actions
end

Instance Method Details

#register_listenersObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/voruby/active_votable/active_votable.rb', line 39

def register_listeners
  self.add_listener(:on_start_element) do |name, attrs|
    if self.actions.has_key?(:on_start_element) and self.actions[:on_start_element].has_key?(name)
      self.actions[:on_start_element][name].call(name, attrs)
    end
  end
    
  self.add_listener(:on_end_element) do |name|
    if self.actions.has_key?(:on_end_element) and self.actions[:on_end_element].has_key?(name)
      self.actions[:on_end_element][name].call(name)
    end
  end
    
  self.add_listener(:on_characters) do |chars|
    self.actions[:on_characters].call(chars) if self.actions.has_key?(:on_characters)
  end
    
  self.add_listener(:on_cdata_block) do |cdata|
    self.actions[:on_cdata_block].call(cdata) if self.actions.has_key?(:on_cdata_block)
  end
    
end