Class: Bio::NeXML::Trees
- Inherits:
-
Object
- Object
- Bio::NeXML::Trees
- Includes:
- Mapper
- Defined in:
- lib/bio/db/nexml/trees.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#label ⇒ Object
Returns the value of attribute label.
Instance Method Summary collapse
-
#<<(object) ⇒ Object
Add a tree or a network to self.
-
#[](id) ⇒ Object
Fetch a tree or a network by id.
-
#add_tree ⇒ Object
Add a tree to self.
-
#count ⇒ Object
(also: #length)
Returns total number of trees and networks.
- #create_network(int = false, options = {}) ⇒ Object
- #create_tree(int = false, options = {}) ⇒ Object
-
#delete_tree ⇒ Object
Delete a tree from self.
-
#each(&block) ⇒ Object
Iterate over each element.
-
#each_tree(&block) ⇒ Object
Iterate over each tree.
-
#has_network?(tree) ⇒ Boolean
Returns true if the given network is containes in self; false otherwise.
-
#has_tree?(tree) ⇒ Boolean
Returns true if tree is containes in self.
- #include?(object) ⇒ Boolean (also: #has?)
-
#initialize(id = nil, options = {}, &block) ⇒ Trees
constructor
Create a trees object.
-
#number_of_trees ⇒ Object
Returns the number of trees contained in self.
- #to_xml ⇒ Object
Methods included from Mapper
Constructor Details
#initialize(id = nil, options = {}, &block) ⇒ Trees
Create a trees object.
578 579 580 581 582 |
# File 'lib/bio/db/nexml/trees.rb', line 578 def initialize( id = nil, = {}, &block ) @id = id properties( ) unless .empty? block.arity < 1 ? instance_eval( &block ) : block.call( self ) if block_given? end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
565 566 567 |
# File 'lib/bio/db/nexml/trees.rb', line 565 def id @id end |
#label ⇒ Object
Returns the value of attribute label.
566 567 568 |
# File 'lib/bio/db/nexml/trees.rb', line 566 def label @label end |
Instance Method Details
#<<(object) ⇒ Object
Add a tree or a network to self.
591 592 593 594 595 596 597 598 599 |
# File 'lib/bio/db/nexml/trees.rb', line 591 def <<( object ) case object when Network add_network( object ) when Tree add_tree( object ) end self end |
#[](id) ⇒ Object
Fetch a tree or a network by id.
614 615 616 617 |
# File 'lib/bio/db/nexml/trees.rb', line 614 def []( id ) get_tree_by_id( id ) || get_network_by_id( id ) end |
#add_tree ⇒ Object
Add a tree to self.
585 |
# File 'lib/bio/db/nexml/trees.rb', line 585 def add_tree; end |
#count ⇒ Object Also known as: length
Returns total number of trees and networks.
638 639 640 |
# File 'lib/bio/db/nexml/trees.rb', line 638 def count number_of_trees + number_of_networks end |
#create_network(int = false, options = {}) ⇒ Object
558 559 560 561 562 563 |
# File 'lib/bio/db/nexml/trees.rb', line 558 def create_network( int = false, = {} ) type = int ? Bio::NeXML::IntNetwork : Bio::NeXML::FloatNetwork network = type.new( Bio::NeXML.generate_id( type ), ) self << network network end |
#create_tree(int = false, options = {}) ⇒ Object
551 552 553 554 555 556 |
# File 'lib/bio/db/nexml/trees.rb', line 551 def create_tree( int = false, = {} ) type = int ? Bio::NeXML::IntTree : Bio::NeXML::FloatTree tree = type.new( Bio::NeXML.generate_id( type ), ) self << tree tree end |
#delete_tree ⇒ Object
Delete a tree from self.
602 |
# File 'lib/bio/db/nexml/trees.rb', line 602 def delete_tree; end |
#each(&block) ⇒ Object
Iterate over each element. Returns an Enumerator if no block is given.
658 659 660 |
# File 'lib/bio/db/nexml/trees.rb', line 658 def each( &block ) @trees.merge( @networks ).each( &block ) end |
#each_tree(&block) ⇒ Object
Iterate over each tree. Returns an Enumerator if no block is given.
644 |
# File 'lib/bio/db/nexml/trees.rb', line 644 def each_tree( &block ); end |
#has_network?(tree) ⇒ Boolean
Returns true if the given network is containes in self; false otherwise.
623 |
# File 'lib/bio/db/nexml/trees.rb', line 623 def has_network?( tree ); end |
#has_tree?(tree) ⇒ Boolean
Returns true if tree is containes in self.
620 |
# File 'lib/bio/db/nexml/trees.rb', line 620 def has_tree?( tree ); end |
#include?(object) ⇒ Boolean Also known as: has?
625 626 627 628 |
# File 'lib/bio/db/nexml/trees.rb', line 625 def include?( object ) has_tree?( object ) || has_network?( object ) end |
#number_of_trees ⇒ Object
Returns the number of trees contained in self.
632 |
# File 'lib/bio/db/nexml/trees.rb', line 632 def number_of_trees; end |
#to_xml ⇒ Object
537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/bio/db/nexml/trees.rb', line 537 def to_xml node = @@writer.create_node( "trees", @@writer.attributes( self, :id, :label, :otus ) ) self.each_tree do |tree| node << tree.to_xml end self.each_network do |network| node << network.to_xml end node end |