Sha256: 6f8374e06326ebb022b6aaa23b847c149053a1226694c70c2c2d69d177840b39
Contents?: true
Size: 862 Bytes
Versions: 1
Compression:
Stored size: 862 Bytes
Contents
require_relative 'header' require_relative 'stanza' module Obo class Parser STANZA_START = /^\[(.*?)\]/ TAG_VALUE = /^(.*?):\s*([^!]*)\s*(.*?)\n/ def initialize(filename) @io = File.open(filename) end def elements(io = @io) Enumerator.new do |yielder| header = Header.new while io.gets.match TAG_VALUE header.add($1, $2) end yielder << header io.gets until $_.match(STANZA_START) stanza = Stanza.new($1.strip) while io.gets case $_ when TAG_VALUE stanza.add($1, $2.strip) when STANZA_START yielder << stanza stanza = Stanza.new($1.strip) end end yielder << stanza rewind end end def rewind(io = @io) io.pos = 0 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
obo-0.1.5 | lib/obo/parser.rb |