Class: Nexml::Handler
- Inherits:
- 
      Object
      
        - Object
- Nexml::Handler
 
- Includes:
- REXML::StreamListener
- Defined in:
- lib/nexml.rb
Overview
code to read the file, the lexer/parser
Instance Method Summary collapse
- 
  
    
      #initialize(obj)  ⇒ Handler 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Handler. 
- 
  
    
      #tag_start(name, attrs)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    hit at the start of an element tag. 
- 
  
    
      #text(text)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    in between elements. 
Constructor Details
#initialize(obj) ⇒ Handler
Returns a new instance of Handler.
| 34 35 36 | # File 'lib/nexml.rb', line 34 def initialize(obj) @obj = obj end | 
Instance Method Details
#tag_start(name, attrs) ⇒ Object
hit at the start of an element tag
| 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | # File 'lib/nexml.rb', line 40 def tag_start name, attrs # puts "processing: #{name}" # These are more or less equivalent to tokens, # they could likely be abstracted to a single # klass-like calls case name when "otus" # it's always a new object @obj.current_obj = @obj.new_otus(attrs) @obj.current_otus = @obj.current_obj when "otu" # it's always in a otus block @obj.current_obj = @obj.new_otu(attrs) when "characters" @obj.current_obj = @obj.new_characters(attrs) @obj.current_characters = @obj.current_obj when "char" @obj.current_obj = @obj.new_char(attrs) when "trees" @obj.current_obj = @obj.new_trees(attrs) @obj.current_trees = @obj.current_obj when "tree" @obj.current_obj = @obj.new_tree(attrs) @obj.current_tree = @obj.current_obj when "node" @obj.current_obj = @obj.new_node(attrs) when "edge" @obj.current_obj = @obj.new_edge(attrs) else # necessary? end end | 
#text(text) ⇒ Object
in between elements
| 73 74 75 76 77 78 79 | # File 'lib/nexml.rb', line 73 def text text t = text.strip # *** NOTE *** # need to test to see that this doesn't have problems with embedded elements like so # <foo>alskfjaslkdfjlasfj <br/> </foo> @obj.current_obj.text = t if @obj.current_obj && t.size > 0 end |