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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bio-alignment/elements.rb', line 35 def initialize id, seq @id = id @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.
34 35 36 |
# File 'lib/bio-alignment/elements.rb', line 34 def id @id end |
#seq ⇒ Object (readonly)
Returns the value of attribute seq.
34 35 36 |
# File 'lib/bio-alignment/elements.rb', line 34 def seq @seq end |
Instance Method Details
#<<(element) ⇒ Object
67 68 69 |
# File 'lib/bio-alignment/elements.rb', line 67 def << element @seq << element end |
#[](index) ⇒ Object
51 52 53 |
# File 'lib/bio-alignment/elements.rb', line 51 def [] index @seq[index] end |
#clone ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/bio-alignment/elements.rb', line 75 def clone copy = Elements.new(@id,"") @seq.each do |e| copy << e.dup end copy end |
#each ⇒ Object
59 60 61 |
# File 'lib/bio-alignment/elements.rb', line 59 def each @seq.each { |e| yield e } end |
#empty_copy ⇒ Object
71 72 73 |
# File 'lib/bio-alignment/elements.rb', line 71 def empty_copy Elements.new(@id,"") end |
#length ⇒ Object
55 56 57 |
# File 'lib/bio-alignment/elements.rb', line 55 def length @seq.length end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/bio-alignment/elements.rb', line 63 def to_s @seq.map{|e| e.to_s }.join("") end |