class Bio::NeXML::Cell

Cell is the smallest unit of a character state matrix or of a sequence. A cell maybe bound or unbound. If a cell points to a char and has a state, it is a bound cell. Bound cells correspond to the cell tag of NeXML. Value of a bound cell is the same as the ‘symbol’ of the state it points to. Value of a bound cell may be changed by assigning a different state to it. An unbound cell holds a raw value.

cell = Bio::NeXML::Cell.new( 'A' )
cell.bound?           #=> false
cell.value            #=> 'A'

# Assign a new value to an unbound cell.
cell.value = 'B'
cell.value            #=> 'B'

cell = Bio::NeXML::Cell.new( :char => char1, :state => stateA )
cell.bound?           #=> true
cell.value            #=> 'A'

# Can not assign a value to a bound cell directly.
cell.value = 'B'
cell.value            #=> 'A'

# Changing the state of a bound cell changes its value.
cell.state = stateB
cell.value            #=> 'B'

Attributes

char[RW]
label[RW]
state[RW]

Public Class Methods

new( char = nil, state = nil, options = {} ) click to toggle source
# File lib/bio/db/nexml/matrix.rb, line 436
def initialize( char = nil, state = nil, options = {} )
  case char
  when Hash
    properties( char )
  when Char
    self.char = char
  else
    @value = char unless char.nil?
  end

  case state
  when State
    self.state = state
  when Hash
    properties( state )
  end

  properties( options ) unless options.nil?
end

Public Instance Methods

bound?() click to toggle source
# File lib/bio/db/nexml/matrix.rb, line 466
def bound?
  !!( char and state )
end
symbol()
Alias for: value
to_s()
Alias for: to_str
to_str() click to toggle source

Allow cells to be implicitly used as a String.

# File lib/bio/db/nexml/matrix.rb, line 471
def to_str
  value.to_s
end
Also aliased as: to_s
to_xml() click to toggle source
# File lib/bio/db/nexml/matrix.rb, line 476
def to_xml
  @@writer.create_node( "cell", @@writer.attributes( self, :state, :char ) )
end
value() click to toggle source

Return the value of a cell.

# File lib/bio/db/nexml/matrix.rb, line 457
def value
  bound? ? state.symbol : @value
end
Also aliased as: symbol
value=( value ) click to toggle source
# File lib/bio/db/nexml/matrix.rb, line 462
def value=( value )
  bound? ? nil : @value = value
end