Class: Bio::NeXML::Cell
- Inherits:
-
Object
- Object
- Bio::NeXML::Cell
- Includes:
- Mapper
- Defined in:
- lib/bio/db/nexml/matrix.rb
Overview
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'
Direct Known Subclasses
Constant Summary collapse
Instance Attribute Summary collapse
-
#char ⇒ Object
Returns the value of attribute char.
-
#label ⇒ Object
Returns the value of attribute label.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #bound? ⇒ Boolean
-
#initialize(char = nil, state = nil, options = {}) ⇒ Cell
constructor
A new instance of Cell.
-
#to_str ⇒ Object
(also: #to_s)
Allow cells to be implicitly used as a String.
- #to_xml ⇒ Object
-
#value ⇒ Object
(also: #symbol)
Return the value of a cell.
- #value=(value) ⇒ Object
Methods included from Mapper
Constructor Details
#initialize(char = nil, state = nil, options = {}) ⇒ Cell
Returns a new instance of Cell.
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/bio/db/nexml/matrix.rb', line 436 def initialize( char = nil, state = nil, = {} ) 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( ) unless .nil? end |
Instance Attribute Details
#char ⇒ Object
Returns the value of attribute char.
426 427 428 |
# File 'lib/bio/db/nexml/matrix.rb', line 426 def char @char end |
#label ⇒ Object
Returns the value of attribute label.
428 429 430 |
# File 'lib/bio/db/nexml/matrix.rb', line 428 def label @label end |
#state ⇒ Object
Returns the value of attribute state.
427 428 429 |
# File 'lib/bio/db/nexml/matrix.rb', line 427 def state @state end |
Instance Method Details
#bound? ⇒ Boolean
466 467 468 |
# File 'lib/bio/db/nexml/matrix.rb', line 466 def bound? !!( char and state ) end |
#to_str ⇒ Object Also known as: to_s
Allow cells to be implicitly used as a String.
471 472 473 |
# File 'lib/bio/db/nexml/matrix.rb', line 471 def to_str value.to_s end |
#to_xml ⇒ Object
476 477 478 |
# File 'lib/bio/db/nexml/matrix.rb', line 476 def to_xml @@writer.create_node( "cell", @@writer.attributes( self, :state, :char ) ) end |
#value ⇒ Object Also known as: symbol
Return the value of a cell.
457 458 459 |
# File 'lib/bio/db/nexml/matrix.rb', line 457 def value bound? ? state.symbol : @value end |
#value=(value) ⇒ Object
462 463 464 |
# File 'lib/bio/db/nexml/matrix.rb', line 462 def value=( value ) bound? ? nil : @value = value end |