class Bio::NeXML::Otus
DESCRIPTION¶ ↑
Otus
is a container for Otu
objects; an implementation of the Taxa[http://nexml.org/nexml/html/doc/schema-1/taxa/taxa/#Taxa] type. An Otus
must have an ‘id’ and may take an optional ‘label’. Adding two or more Otu
objects with the same ‘id’ to an Otus
is not allowed. Doing so will overwrite the previous Otu
object with the same the same ‘id’.
taxa1 = Bio::NeXML::Otus.new( 'taxa1', :label => 'Label for taxa1' ) taxa1.id #=> 'taxa1' taxa1.label #=> 'Label for taxa1' taxon1 = Bio::NeXML::Otu.new( 'taxon1' ) taxon2 = Bio::NeXML::Otu.new( 'taxon2' ) taxa1 << taxon1 << taxon2 taxa1.count #=> 2 taxa1.each { |otu| puts otu.id } taxon2.otus #=> taxa1 taxa1.include?( taxon1 ) #=> true taxa1.delete( taxon2 ) #=> taxon2
Attributes
A file level unique identifier.
A human readable description.
Public Class Methods
# File lib/bio/db/nexml/taxa.rb, line 80 def initialize( id, options = {}, &block ) @id = id properties( options ) unless options.empty? block.arity < 1 ? instance_eval( &block ) : block.call( self ) if block_given? end
Public Instance Methods
Takes an otu object and appends it to self
.
# File lib/bio/db/nexml/taxa.rb, line 92 def <<( otu ) add_otu( otu ) self end
Returns the otu object with the given id; nil
if an otu with the given id is not contained in self
.
# File lib/bio/db/nexml/taxa.rb, line 116 def []( id ) get_otu_by_id( id ) end
Creates and returns an otu after appending it to self
# File lib/bio/db/nexml/taxa.rb, line 98 def create_otu( options = {} ) otu = Otu.new( Bio::NeXML.generate_id( Otu ), options ) self << otu otu end
Takes an otu or its id and deletes it. Returns the object deleted or nil
.
# File lib/bio/db/nexml/taxa.rb, line 105 def delete( otu ) delete_otu( otu ) end
Iterate over each otu in self
passing it to the block given. If no block is provided, it returns an Enumerator.
# File lib/bio/db/nexml/taxa.rb, line 122 def each( &block ) @otus.each( &block ) end
Iterate over each otu in self
passing the otu and its id to the block given. If no block is provided, it returns an Enumerator.
# File lib/bio/db/nexml/taxa.rb, line 128 def each_with_id( &block ) @otus.each_with_id( &block ) end
Takes an otu or its id and returns true
if it is contained in self
.
# File lib/bio/db/nexml/taxa.rb, line 110 def include?( object ) has_otu?( object ) end
Return the number of otu in self
.
# File lib/bio/db/nexml/taxa.rb, line 133 def length number_of_otus end
Returns an array of otu contained in self
.
# File lib/bio/db/nexml/taxa.rb, line 87 def otus; end
Taken an array of otu and adds it to self
.
# File lib/bio/db/nexml/taxa.rb, line 89 def otus=; end
# File lib/bio/db/nexml/taxa.rb, line 137 def to_xml node = @@writer.create_node( "otus", @@writer.attributes( self, :id, :label ) ) self.each do |otu| node << otu.to_xml end node end