Class: Obo::Parser

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

Constant Summary collapse

STANZA_START =
/^\[(.*?)\]/
TAG_VALUE =
/^(.*?):([^!]*)/

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Parser

Returns a new instance of Parser.



9
10
11
12
# File 'lib/obo/parser.rb', line 9

def initialize(filename)
  @header = nil
  @io     = File.open(filename)
end

Instance Method Details

#elements(io = @io) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/obo/parser.rb', line 14

def elements(io = @io)
  Enumerator.new do |yielder|
    header             = Header.new
    prev_line_position = io.pos
    line               = lines.next

    until line.is_a? Stanza
      header.add(*line)
      prev_line_position = io.pos
      line               = lines.next
    end

    yielder << header
    io.pos = prev_line_position

    stanzas.each { |stanza| yielder << stanza }
  end
end

#rewind(io = @io) ⇒ Object



33
34
35
# File 'lib/obo/parser.rb', line 33

def rewind(io = @io)
  io.pos = 0
end