Class: Bio::NeXML::Otus
- Inherits:
-
Object
- Object
- Bio::NeXML::Otus
- Includes:
- Mapper, Enumerable
- Defined in:
- lib/bio/db/nexml/taxa.rb
Overview
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
Constant Summary collapse
Instance Attribute Summary collapse
-
#id ⇒ Object
A file level unique identifier.
-
#label ⇒ Object
A human readable description.
Instance Method Summary collapse
-
#<<(otu) ⇒ Object
Takes an otu object and appends it to
self
. -
#[](id) ⇒ Object
Returns the otu object with the given id;
nil
if an otu with the given id is not contained inself
. -
#create_otu(options = {}) ⇒ Object
Creates and returns an otu after appending it to self.
-
#delete(otu) ⇒ Object
Takes an otu or its id and deletes it.
-
#each(&block) ⇒ Object
Iterate over each otu in
self
passing it to the block given. -
#each_with_id(&block) ⇒ Object
Iterate over each otu in
self
passing the otu and its id to the block given. -
#include?(object) ⇒ Boolean
Takes an otu or its id and returns
true
if it is contained inself
. -
#initialize(id, options = {}, &block) ⇒ Otus
constructor
A new instance of Otus.
-
#length ⇒ Object
Return the number of otu in
self
. -
#otus ⇒ Object
Returns an array of otu contained in
self
. - #to_xml ⇒ Object
Methods included from Mapper
Constructor Details
#initialize(id, options = {}, &block) ⇒ Otus
Returns a new instance of Otus.
80 81 82 83 84 |
# File 'lib/bio/db/nexml/taxa.rb', line 80 def initialize( id, = {}, &block ) @id = id properties( ) unless .empty? block.arity < 1 ? instance_eval( &block ) : block.call( self ) if block_given? end |
Instance Attribute Details
#id ⇒ Object
A file level unique identifier.
69 70 71 |
# File 'lib/bio/db/nexml/taxa.rb', line 69 def id @id end |
#label ⇒ Object
A human readable description.
72 73 74 |
# File 'lib/bio/db/nexml/taxa.rb', line 72 def label @label end |
Instance Method Details
#<<(otu) ⇒ Object
Takes an otu object and appends it to self
.
92 93 94 95 |
# File 'lib/bio/db/nexml/taxa.rb', line 92 def <<( otu ) add_otu( otu ) self end |
#[](id) ⇒ Object
Returns the otu object with the given id; nil
if an otu with the given id is not contained in self
.
116 117 118 |
# File 'lib/bio/db/nexml/taxa.rb', line 116 def []( id ) get_otu_by_id( id ) end |
#create_otu(options = {}) ⇒ Object
Creates and returns an otu after appending it to self
98 99 100 101 102 |
# File 'lib/bio/db/nexml/taxa.rb', line 98 def create_otu( = {} ) otu = Otu.new( Bio::NeXML.generate_id( Otu ), ) self << otu otu end |
#delete(otu) ⇒ Object
Takes an otu or its id and deletes it. Returns the object deleted or nil
.
105 106 107 |
# File 'lib/bio/db/nexml/taxa.rb', line 105 def delete( otu ) delete_otu( otu ) end |
#each(&block) ⇒ Object
Iterate over each otu in self
passing it to the block given. If no block is provided, it returns an Enumerator.
122 123 124 |
# File 'lib/bio/db/nexml/taxa.rb', line 122 def each( &block ) @otus.each( &block ) end |
#each_with_id(&block) ⇒ Object
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.
128 129 130 |
# File 'lib/bio/db/nexml/taxa.rb', line 128 def each_with_id( &block ) @otus.each_with_id( &block ) end |
#include?(object) ⇒ Boolean
Takes an otu or its id and returns true
if it is contained in self
.
110 111 112 |
# File 'lib/bio/db/nexml/taxa.rb', line 110 def include?( object ) has_otu?( object ) end |
#length ⇒ Object
Return the number of otu in self
.
133 134 135 |
# File 'lib/bio/db/nexml/taxa.rb', line 133 def length number_of_otus end |
#otus ⇒ Object
Returns an array of otu contained in self
.
87 |
# File 'lib/bio/db/nexml/taxa.rb', line 87 def otus; end |
#to_xml ⇒ Object
137 138 139 140 141 142 143 |
# 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 |