Class: Bio::NeXML::State
- Inherits:
-
Object
- Object
- Bio::NeXML::State
- Includes:
- Mapper, Enumerable
- Defined in:
- lib/bio/db/nexml/matrix.rb
Overview
State defines a possible observation with its ‘symbol’ attribute. A state may be ambiguous. An ambiguous state must define an ambiguity mapping which may be ‘polymorphic’, resolved in an ‘and’ context, or uncertain, resolved in a ‘or’ context.
state = Bio::NeXML::State.new( 'state1', :label => 'A label' )
state.id #=> 'state1'
state.label #=> 'A label'
state.ambiguous? #=> true
state.ambiguity #=> :polymorphic
Constant Summary collapse
Instance Attribute Summary collapse
-
#ambiguity ⇒ Object
Polymorphic or uncertain.
-
#id ⇒ Object
A file level unique identifier.
-
#label ⇒ Object
A human readable description of the state.
-
#symbol ⇒ Object
Observation for this state.
Class Method Summary collapse
- .polymorphic(id, symbol = nil, options = {}, &block) ⇒ Object
- .uncertain(id, symbol = nil, options = {}, &block) ⇒ Object
Instance Method Summary collapse
-
#add_member(member) ⇒ Object
Takes a Bio::NeXML::State object and adds it to the ambiguity mapping of the state.
- #ambiguous? ⇒ Boolean
- #count ⇒ Object (also: #length)
-
#each(&block) ⇒ Object
Iterate over each member in
self
passing it to the block given. - #include?(member) ⇒ Boolean
-
#initialize(id, symbol = nil, options = {}, &block) ⇒ State
constructor
A new instance of State.
- #polymorphic? ⇒ Boolean
- #to_str ⇒ Object (also: #to_s)
- #to_xml ⇒ Object
- #uncertain? ⇒ Boolean
Methods included from Mapper
Constructor Details
#initialize(id, symbol = nil, options = {}, &block) ⇒ State
Returns a new instance of State.
40 41 42 43 44 45 |
# File 'lib/bio/db/nexml/matrix.rb', line 40 def initialize( id, symbol = nil, = {}, &block ) @id = id symbol.is_a?( Hash ) ? = symbol : self.symbol = symbol properties( ) unless .empty? block.arity < 1 ? instance_eval( &block ) : block.call( self ) if block_given? end |
Instance Attribute Details
#ambiguity ⇒ Object
Polymorphic or uncertain.
24 25 26 |
# File 'lib/bio/db/nexml/matrix.rb', line 24 def ambiguity @ambiguity end |
#id ⇒ Object
A file level unique identifier.
18 19 20 |
# File 'lib/bio/db/nexml/matrix.rb', line 18 def id @id end |
#label ⇒ Object
A human readable description of the state.
27 28 29 |
# File 'lib/bio/db/nexml/matrix.rb', line 27 def label @label end |
#symbol ⇒ Object
Observation for this state.
21 22 23 |
# File 'lib/bio/db/nexml/matrix.rb', line 21 def symbol @symbol end |
Class Method Details
.polymorphic(id, symbol = nil, options = {}, &block) ⇒ Object
106 107 108 109 110 |
# File 'lib/bio/db/nexml/matrix.rb', line 106 def polymorphic( id, symbol = nil, = {}, &block ) state = new( id, symbol, , &block ) state.ambiguity = :polymorphic state end |
.uncertain(id, symbol = nil, options = {}, &block) ⇒ Object
112 113 114 115 116 |
# File 'lib/bio/db/nexml/matrix.rb', line 112 def uncertain( id, symbol = nil, = {}, &block ) state = new( id, symbol, , &block ) state.ambiguity = :uncertain state end |
Instance Method Details
#add_member(member) ⇒ Object
Takes a Bio::NeXML::State object and adds it to the ambiguity mapping of the state. Returns # self
.
53 |
# File 'lib/bio/db/nexml/matrix.rb', line 53 def add_member( member ); end |
#ambiguous? ⇒ Boolean
55 56 57 |
# File 'lib/bio/db/nexml/matrix.rb', line 55 def ambiguous? !!ambiguity end |
#count ⇒ Object Also known as: length
71 72 73 |
# File 'lib/bio/db/nexml/matrix.rb', line 71 def count number_of_members end |
#each(&block) ⇒ Object
Iterate over each member in self
passing it to the block given. If no block is provided, it returns an Enumerator.
78 79 80 |
# File 'lib/bio/db/nexml/matrix.rb', line 78 def each( &block ) @members.each( &block ) end |
#include?(member) ⇒ Boolean
67 68 69 |
# File 'lib/bio/db/nexml/matrix.rb', line 67 def include?( member ) has_member?( member ) end |
#polymorphic? ⇒ Boolean
59 60 61 |
# File 'lib/bio/db/nexml/matrix.rb', line 59 def polymorphic? ambiguity == :polymorphic end |
#to_str ⇒ Object Also known as: to_s
82 83 84 |
# File 'lib/bio/db/nexml/matrix.rb', line 82 def to_str symbol.to_s end |
#to_xml ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/bio/db/nexml/matrix.rb', line 87 def to_xml tagname = nil if ambiguity == :polymorphic tagname = "polymorphic_state_set" elsif ambiguity == :uncertain tagname = "uncertain_state_set" else tagname = "state" end node = @@writer.create_node( tagname, @@writer.attributes( self, :id, :label, :symbol ) ) if count > 0 self.each_member do |member| node << @@writer.create_node( "member", :state => member.id ) end end node end |
#uncertain? ⇒ Boolean
63 64 65 |
# File 'lib/bio/db/nexml/matrix.rb', line 63 def uncertain? ambiguity == :uncertain end |