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.



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

#idObject (readonly)

Returns the value of attribute id.



42
43
44
# File 'lib/bio-alignment/elements.rb', line 42

def id
  @id
end

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

#cloneObject



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

#eachObject



68
69
70
# File 'lib/bio-alignment/elements.rb', line 68

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

#empty_copyObject



80
81
82
# File 'lib/bio-alignment/elements.rb', line 80

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

#lengthObject



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

def length
  @seq.length
end

#to_sObject



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

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