Class: Bio::NeXML::Format

Inherits:
Object
  • Object
show all
Includes:
Mapper
Defined in:
lib/bio/db/nexml/matrix.rb

Constant Summary collapse

@@writer =
Bio::NeXML::Writer.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mapper

#properties

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( options = {} )
  @id = self.object_id
  properties( options ) unless options.empty?
  block.arity < 1 ? instance_eval( &block ) : block.call( self ) if block_given?
end

Instance Attribute Details

#idObject

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, options = {} )
  char = Char.new( Bio::NeXML.generate_id( Char ), states, options )
  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( options = {} )
  states = States.new( Bio::NeXML.generate_id( States ), options )
  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.

Returns:

  • (Boolean)


351
352
353
# File 'lib/bio/db/nexml/matrix.rb', line 351

def has_states?( states )
  # dummy for rdoc
end

#to_xmlObject



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