Class: Bio::BioAlignment::Elements
- Inherits:
-
Object
- Object
- Bio::BioAlignment::Elements
- Includes:
- State, Enumerable
- Defined in:
- lib/bio-alignment/elements.rb
Overview
Elements is a container for Element sequences.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#seq ⇒ Object
readonly
Returns the value of attribute seq.
Attributes included from State
Instance Method Summary collapse
- #<<(element) ⇒ Object
- #[](index) ⇒ Object
- #clone ⇒ Object
- #each ⇒ Object
- #empty_copy ⇒ Object
-
#initialize(id, seq) ⇒ Elements
constructor
A new instance of Elements.
- #length ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(id, seq) ⇒ Elements
Returns a new instance of Elements.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bio-alignment/elements.rb', line 43 def initialize id, seq @id = id @id.freeze @seq = [] if seq.kind_of?(Elements) @seq = seq.clone elsif seq.kind_of?(String) seq.each_char do |c| @seq << Element.new(c) end else seq.each do |s| @seq << Element.new(s) end end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
42 43 44 |
# File 'lib/bio-alignment/elements.rb', line 42 def id @id end |
#seq ⇒ Object (readonly)
Returns the value of attribute seq.
42 43 44 |
# File 'lib/bio-alignment/elements.rb', line 42 def seq @seq end |
Instance Method Details
#<<(element) ⇒ Object
76 77 78 |
# File 'lib/bio-alignment/elements.rb', line 76 def << element @seq << element end |
#[](index) ⇒ Object
60 61 62 |
# File 'lib/bio-alignment/elements.rb', line 60 def [] index @seq[index] end |
#clone ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/bio-alignment/elements.rb', line 84 def clone copy = Elements.new(@id,"") @seq.each do |e| copy << e.clone end copy end |
#each ⇒ Object
68 69 70 |
# File 'lib/bio-alignment/elements.rb', line 68 def each @seq.each { |e| yield e } end |
#empty_copy ⇒ Object
80 81 82 |
# File 'lib/bio-alignment/elements.rb', line 80 def empty_copy Elements.new(@id,"") end |
#length ⇒ Object
64 65 66 |
# File 'lib/bio-alignment/elements.rb', line 64 def length @seq.length end |
#to_s ⇒ Object
72 73 74 |
# File 'lib/bio-alignment/elements.rb', line 72 def to_s @seq.map{|e| e.to_s }.join("") end |