Class: Bio::Nexus::GenericBlock
Overview
DESCRIPTION
Bio::Nexus::GenericBlock represents a generic nexus block. It is mainly intended to be extended into more specific classes, although it is used for blocks not represented by more specific block classes. It has a name and a array for the tokenized content of a nexus block.
USAGE
require 'bio/db/nexus'
# Create a new parser:
nexus = Bio::Nexus.new( nexus_data_as_string )
# Get blocks for which no class exists (private blocks)
as Nexus::GenericBlock:
private_blocks = nexus.get_blocks_by_name( "my_block" )
# Get first block names "my_block":
my_block_0 = private_blocks[ 0 ]
# Get first token in first block names "my_block":
first_token = my_block_0.get_tokens[ 0 ]
# Get name of block (would return "my_block" in this case):
name = my_block_0.get_name
# Return data of block as nexus formatted String:
name = my_block_0.to_nexus
Direct Known Subclasses
Instance Method Summary collapse
-
#add_token(token) ⇒ Object
Adds a token to this.
-
#get_name ⇒ Object
Gets the name of this block.
-
#get_tokens ⇒ Object
Returns contents as Array of Strings.
-
#initialize(name) ⇒ GenericBlock
constructor
Creates a new GenericBlock object named ‘name’.
-
#to_nexus ⇒ Object
Should return a String describing this block as nexus formatted data.
-
#to_s ⇒ Object
(also: #to_str)
Same as to_nexus.
Constructor Details
#initialize(name) ⇒ GenericBlock
Creates a new GenericBlock object named ‘name’.
Arguments:
-
(required) name: String
775 776 777 778 |
# File 'lib/bio/db/nexus.rb', line 775 def initialize( name ) @name = name.chomp(";") @tokens = Array.new end |
Instance Method Details
#add_token(token) ⇒ Object
Adds a token to this.
Arguments:
-
(required) token: String
817 818 819 |
# File 'lib/bio/db/nexus.rb', line 817 def add_token( token ) @tokens.push( token ) end |
#get_name ⇒ Object
Gets the name of this block.
- Returns
-
String
784 785 786 |
# File 'lib/bio/db/nexus.rb', line 784 def get_name @name end |
#get_tokens ⇒ Object
Returns contents as Array of Strings.
- Returns
-
Array
792 793 794 |
# File 'lib/bio/db/nexus.rb', line 792 def get_tokens @tokens end |
#to_nexus ⇒ Object
Should return a String describing this block as nexus formatted data.
- Returns
-
String
808 809 810 |
# File 'lib/bio/db/nexus.rb', line 808 def to_nexus str = "generic block \"" + get_name + "\" [do not know how to write in nexus format]" end |
#to_s ⇒ Object Also known as: to_str
Same as to_nexus.
- Returns
-
String
800 801 802 |
# File 'lib/bio/db/nexus.rb', line 800 def to_s to_nexus end |