Class: Bio::NeXML::Format
- Inherits:
-
Object
- Object
- Bio::NeXML::Format
- Includes:
- Mapper
- Defined in:
- lib/bio/db/nexml/matrix.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#id ⇒ Object
Because format elements don’t have id attributes, we will use object_id in this case.
Instance Method Summary collapse
- #add_states(states) ⇒ Object
- #create_char(states = nil, options = {}) ⇒ Object
- #create_states(options = {}) ⇒ Object
-
#get_char_by_id(id) ⇒ Object
Fetch a column definition( Bio::NeXML::Char object ) by id.
-
#has_states?(states) ⇒ Boolean
Returns true if the given state set( Bio::NeXML::States object ) is defined for the matrix.
-
#initialize(options = {}) ⇒ Format
constructor
A new instance of Format.
- #to_xml ⇒ Object
Methods included from Mapper
Constructor Details
#initialize(options = {}) ⇒ Format
Returns a new instance of Format.
233 234 235 236 237 |
# File 'lib/bio/db/nexml/matrix.rb', line 233 def initialize( = {} ) @id = self.object_id properties( ) unless .empty? block.arity < 1 ? instance_eval( &block ) : block.call( self ) if block_given? end |
Instance Attribute Details
#id ⇒ Object
Because format elements don’t have id attributes, we will use object_id in this case
231 232 233 |
# File 'lib/bio/db/nexml/matrix.rb', line 231 def id @id end |
Instance Method Details
#add_states(states) ⇒ Object
251 252 253 |
# File 'lib/bio/db/nexml/matrix.rb', line 251 def add_states( states ) # dummy for rdoc end |
#create_char(states = nil, options = {}) ⇒ Object
245 246 247 248 249 |
# File 'lib/bio/db/nexml/matrix.rb', line 245 def create_char( states = nil, = {} ) char = Char.new( Bio::NeXML.generate_id( Char ), states, ) add_char char char end |
#create_states(options = {}) ⇒ Object
239 240 241 242 243 |
# File 'lib/bio/db/nexml/matrix.rb', line 239 def create_states( = {} ) states = States.new( Bio::NeXML.generate_id( States ), ) add_states states states end |
#get_char_by_id(id) ⇒ Object
Fetch a column definition( Bio::NeXML::Char object ) by id. Returns nil
if none found.
345 346 347 348 |
# File 'lib/bio/db/nexml/matrix.rb', line 345 def get_char_by_id( id ) matches = each_char.select{ |c| c.id == id } # XXX not sure why I have to implement this? matches.first end |
#has_states?(states) ⇒ Boolean
Returns true if the given state set( Bio::NeXML::States object ) is defined for the matrix.
351 352 353 |
# File 'lib/bio/db/nexml/matrix.rb', line 351 def has_states?( states ) # dummy for rdoc end |
#to_xml ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/bio/db/nexml/matrix.rb', line 382 def to_xml node = @@writer.create_node( "format" ) self.each_states do |states| node << states.to_xml end self.each_char do |char| node << char.to_xml end node end |