Class: Bio::MAF::Struct

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/maf/struct.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ Struct

Returns a new instance of Struct.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bio/maf/struct.rb', line 12

def initialize(spec)
  @members = []
  @by_name = {}
  offset = 0
  spec.each do |m_spec|
    m = Member.new(offset, *m_spec)
    @members << m
    @by_name[m.name] = m
    offset += m.size
  end
  @size = offset
end

Instance Attribute Details

#sizeObject (readonly)



10
11
12
# File 'lib/bio/maf/struct.rb', line 10

def size
  @size
end

Instance Method Details

#extractor_fmt(*names) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bio/maf/struct.rb', line 29

def extractor_fmt(*names)
  extract = names.collect { |name| @by_name.fetch(name) }
  extract.sort_by! { |m| m.offset }
  fmt = ''
  pos = 0
  extract.each do |member|
    if member.offset != pos
      fmt << "@#{member.offset}"
      pos = member.offset
    end
    fmt << member.fmt
    pos += member.size
  end
  return fmt
end

#fmtObject



25
26
27
# File 'lib/bio/maf/struct.rb', line 25

def fmt
  @members.collect { |m| m.fmt }.join('')
end