Class: Sam::Header::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/sam.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ Record

Returns a new instance of Record.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sam.rb', line 14

def initialize line
  @line = line
  if line =~ /^@CO\t(.*)/
    @type = :CO
    @comment = $1
  end
  line.match /^@([A-Za-z][A-Za-z])\t((?:[A-Za-z][A-Za-z0-9]:[ -~]+(?:\t|$))+)/ do |m|
    @type = m[1].to_sym
    @tags = Hash[m[2].split(/\t/).map{|s| s.split(/:/)}]
  end
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



11
12
13
# File 'lib/sam.rb', line 11

def comment
  @comment
end

#lineObject (readonly)

Returns the value of attribute line.



12
13
14
# File 'lib/sam.rb', line 12

def line
  @line
end

#tagsObject (readonly)

Returns the value of attribute tags.



10
11
12
# File 'lib/sam.rb', line 10

def tags
  @tags
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/sam.rb', line 9

def type
  @type
end

Instance Method Details

#to_sObject



26
27
28
29
30
31
32
# File 'lib/sam.rb', line 26

def to_s
  if @type == :CO
    "@#{@type}\t#{@comment}"
  else
    "@#{@type}\t#{tags.map{ |t,v| "#{t}:#{v}" }.join("\t")}"
  end
end