Class: Nexml::Document
Overview
model of the NeXML file
Defined Under Namespace
Classes: Annotation, Char, Characters, Coding, Edge, Matrix, Node, Otu, Otus, State, Tree, Trees
Instance Attribute Summary collapse
- 
  
    
      #characters  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    these three are the top level grouping classes. 
- 
  
    
      #current_characters  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    stores the present state as we stream through the file, these may not all be necessary and can likely be abstracted down to a single :current_parent_object. 
- 
  
    
      #current_matrix  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    stores the present state as we stream through the file, these may not all be necessary and can likely be abstracted down to a single :current_parent_object. 
- 
  
    
      #current_obj  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    stores the present state as we stream through the file, these may not all be necessary and can likely be abstracted down to a single :current_parent_object. 
- 
  
    
      #current_otus  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    stores the present state as we stream through the file, these may not all be necessary and can likely be abstracted down to a single :current_parent_object. 
- 
  
    
      #current_tree  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    stores the present state as we stream through the file, these may not all be necessary and can likely be abstracted down to a single :current_parent_object. 
- 
  
    
      #current_trees  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    stores the present state as we stream through the file, these may not all be necessary and can likely be abstracted down to a single :current_parent_object. 
- 
  
    
      #otus  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    these three are the top level grouping classes. 
- 
  
    
      #trees  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    these three are the top level grouping classes. 
Attributes inherited from DummyBase
Instance Method Summary collapse
- #all_chrs ⇒ Object
- #all_otus ⇒ Object
- #all_trees ⇒ Object
- 
  
    
      #initialize(options = {})  ⇒ Document 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Document. 
- #new_char(attrs) ⇒ Object
- #new_characters(attrs) ⇒ Object
- #new_edge(attrs) ⇒ Object
- #new_node(attrs) ⇒ Object
- #new_otu(attrs) ⇒ Object
- 
  
    
      #new_otus(attrs)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    setters. 
- #new_tree(attrs) ⇒ Object
- #new_trees(attrs) ⇒ Object
- 
  
    
      #otu_by_id(id)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    getters. 
- #tree_by_id(id) ⇒ Object
Methods inherited from DummyBase
Constructor Details
#initialize(options = {}) ⇒ Document
Returns a new instance of Document.
| 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | # File 'lib/nexml.rb', line 111 def initialize( = {}) @opt = { :file => false, :url => false }.merge!() @otus, @characters, @trees = [],[],[] @current_obj = nil @current_matrix, @current_tree, @current_trees, @current_otus, @current_characters = nil,nil, nil, nil, nil # require a file or a URL raise Nexml::NexmlError, "supply ONLY one of :file or :url" if @opt[:file] && @opt[:url] @nexml = '' if @opt[:file] @nexml = @opt[:file] elsif @opt[:url] @nexml = Net::HTTP.get_response(URI.parse(@opt[:url])).body else raise Nexml::NexmlError, "supply one of :file or :url" if !@opt[:file] && !@opt[:url] end @attributes = {} # do the work REXML::Document.parse_stream(@nexml, Handler.new(self)) true end | 
Instance Attribute Details
#characters ⇒ Object
these three are the top level grouping classes
| 105 106 107 | # File 'lib/nexml.rb', line 105 def characters @characters end | 
#current_characters ⇒ Object
stores the present state as we stream through the file, these may not all be necessary and can likely be abstracted down to a single :current_parent_object
| 109 110 111 | # File 'lib/nexml.rb', line 109 def current_characters @current_characters end | 
#current_matrix ⇒ Object
stores the present state as we stream through the file, these may not all be necessary and can likely be abstracted down to a single :current_parent_object
| 109 110 111 | # File 'lib/nexml.rb', line 109 def current_matrix @current_matrix end | 
#current_obj ⇒ Object
stores the present state as we stream through the file, these may not all be necessary and can likely be abstracted down to a single :current_parent_object
| 109 110 111 | # File 'lib/nexml.rb', line 109 def current_obj @current_obj end | 
#current_otus ⇒ Object
stores the present state as we stream through the file, these may not all be necessary and can likely be abstracted down to a single :current_parent_object
| 109 110 111 | # File 'lib/nexml.rb', line 109 def current_otus @current_otus end | 
#current_tree ⇒ Object
stores the present state as we stream through the file, these may not all be necessary and can likely be abstracted down to a single :current_parent_object
| 109 110 111 | # File 'lib/nexml.rb', line 109 def current_tree @current_tree end | 
#current_trees ⇒ Object
stores the present state as we stream through the file, these may not all be necessary and can likely be abstracted down to a single :current_parent_object
| 109 110 111 | # File 'lib/nexml.rb', line 109 def current_trees @current_trees end | 
#otus ⇒ Object
these three are the top level grouping classes
| 105 106 107 | # File 'lib/nexml.rb', line 105 def otus @otus end | 
#trees ⇒ Object
these three are the top level grouping classes
| 105 106 107 | # File 'lib/nexml.rb', line 105 def trees @trees end | 
Instance Method Details
#all_chrs ⇒ Object
| 206 207 208 | # File 'lib/nexml.rb', line 206 def all_chrs @characters.inject([]){|sum, o| sum.push(o.chars)}.flatten end | 
#all_otus ⇒ Object
| 202 203 204 | # File 'lib/nexml.rb', line 202 def all_otus @otus.inject([]){|sum, o| sum.push(o.otus)}.flatten end | 
#all_trees ⇒ Object
| 210 211 212 | # File 'lib/nexml.rb', line 210 def all_trees @trees.inject([]){|sum, o| sum.push(o.trees)}.flatten end | 
#new_char(attrs) ⇒ Object
| 160 161 162 163 164 | # File 'lib/nexml.rb', line 160 def new_char(attrs) chr = Char.new(:attrs => attrs) self.current_characters.chars.push(chr) chr end | 
#new_characters(attrs) ⇒ Object
| 154 155 156 157 158 | # File 'lib/nexml.rb', line 154 def new_characters(attrs) characters = Characters.new(:attrs => attrs) self.characters.push(characters) characters end | 
#new_edge(attrs) ⇒ Object
| 184 185 186 187 188 | # File 'lib/nexml.rb', line 184 def new_edge(attrs) node = Edge.new(:attrs => attrs) self.current_tree.edges.push(node) node end | 
#new_node(attrs) ⇒ Object
| 178 179 180 181 182 | # File 'lib/nexml.rb', line 178 def new_node(attrs) node = Node.new(:attrs => attrs) self.current_tree.nodes.push(node) node end | 
#new_otu(attrs) ⇒ Object
| 148 149 150 151 152 | # File 'lib/nexml.rb', line 148 def new_otu(attrs) otu = Otu.new(:attrs => attrs) self.current_otus.otus.push(otu) otu end | 
#new_otus(attrs) ⇒ Object
setters
| 142 143 144 145 146 | # File 'lib/nexml.rb', line 142 def new_otus(attrs) otus = Otus.new(:attrs => attrs) self.otus.push(otus) otus end | 
#new_tree(attrs) ⇒ Object
| 172 173 174 175 176 | # File 'lib/nexml.rb', line 172 def new_tree(attrs) tree = Tree.new(:attrs => attrs) self.current_trees.trees.push(tree) tree end | 
#new_trees(attrs) ⇒ Object
| 166 167 168 169 170 | # File 'lib/nexml.rb', line 166 def new_trees(attrs) trees = Trees.new(:attrs => attrs) self.trees.push(trees) trees end | 
#otu_by_id(id) ⇒ Object
getters
| 192 193 194 195 | # File 'lib/nexml.rb', line 192 def otu_by_id(id) foo = self.all_otus.collect{|o| o.attribute('id')} self.all_otus[foo.index(id)] end | 
#tree_by_id(id) ⇒ Object
| 197 198 199 200 | # File 'lib/nexml.rb', line 197 def tree_by_id(id) foo = self.all_trees.collect{|o| o.attribute('id')} self.all_trees[foo.index(id)] end |