Class: Bio::BioAlignment::Elements

Inherits:
Object
  • Object
show all
Includes:
State, Enumerable
Defined in:
lib/bio-alignment/elements.rb

Overview

Elements is a container for Element sequences.

Instance Attribute Summary collapse

Attributes included from State

#state

Instance Method Summary collapse

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

#idObject (readonly)

Returns the value of attribute id.



34
35
36
# File 'lib/bio-alignment/elements.rb', line 34

def id
  @id
end

#seqObject (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

#cloneObject



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

#eachObject



59
60
61
# File 'lib/bio-alignment/elements.rb', line 59

def each
  @seq.each { |e| yield e }
end

#empty_copyObject



71
72
73
# File 'lib/bio-alignment/elements.rb', line 71

def empty_copy
  Elements.new(@id,"")
end

#lengthObject



55
56
57
# File 'lib/bio-alignment/elements.rb', line 55

def length
  @seq.length
end

#to_sObject



63
64
65
# File 'lib/bio-alignment/elements.rb', line 63

def to_s
  @seq.map{|e| e.to_s }.join("")
end