Class MyoPyx
In: /home/ser/Work/Pyx/MyoPyx.rb
Parent: Object
MyoPyx A PYX document parser. Author: Sean Russell <ser@germane-software.com> Version: 1.0

Still to do:

  * Add support for listening for multiple tags with one
  addListener() call.</li>
Methods
add_listener    add_pi_listener    new    parse    remove_listener    remove_pi_listener   
Attributes
listeners  [RW] 
pi_listeners  [RW] 
Classes and Modules
Module MyoPyx::DummyListener
Public Class methods
new()
Public Instance methods
parse( reader )
Parses a Reader stream, generating events that are sent to MyoPyx.Listeners that are added with addListener() or addPIListener().

 p = MyoPyx.new()
 p.addListener( my_listener )
 input = File.new( "my.pyx" )
 p.parse( input )

An exception is raised if there is a problem reading from the reader, or if there is a parsing problem. If there is a parsing exception, such as bad markup or bad document formatting, the error message will contnain the line number where the error occurred.

add_listener(listener, tag_name=nil)
Add a listener for parsing events. The listener must define the methods:
 * start_element( name, attrs ) # name isa String, attrs isa {}
 * end_element( name ) # name isa String
 * text( content ) # content isa String

 class MyTagListener
   include MyoPyx::DummyListener
   def start_element( name, attrs )
     puts "MyTag has attributes:"
     attrs.each_pair { |key, value| puts "\t#{key} -> #{value}" }
 end
 class AllListener
   include MyoPyx::DummyListener
   def start_element( name, attrs )
     puts "Got tag #{name}"
   end
 end
 pyx.addListener( AllListener.new );
 pyx.addListener( MyTagListener.new, "MyTag" )

Listeners for all events will be notified before listeners of specific events. After this, Listeners are notified in the order they are added.

If tag_name is null, the listener will be notified of all events. If it is not null, the listener will be notified of only events pertaining to elements matching the tag_name.

remove_listener(listener, tag_name=nil)
Removes a listener. The tag must match the tag under which the listener was added; for example, if a listener is added as both a "MyTag1" and "MyTag2", then remove_listener(listener) will do nothing, and remove_listener(listener, "MyTag1") will only remove the listener for events on "MyTag1", not "MyTag2".
add_pi_listener(listener)
Attaches a listener of processing instruction (PI) events. The listener must define a pi( text ) method, which will be called when a processing instruction is encountered; the text will be the body of the processing instruction
remove_pi_listener(listener)