Class Rubidium::SDF::Parser
In: lib/rubidium/sdf.rb
Parent: Object

An SD File pull-parser.

Usage:

 require 'rubidium/sdf'

 p=Rubidium::SDF::Parser.new File.new('path/to/sdfile.sdf')

 p.each_with_line_number do |entry, line|
   puts "Entry field 'foo' at line number #{line}: #{entry['foo']}"
 end

Methods

Constants

RECORD_SEPARATOR_REGEX = /^\$\$\$\$/
HEADER_REGEX = /<([^>]+)>/

Attributes

current_line  [R] 
io  [R] 

Public Class methods

[Source]

    # File lib/rubidium/sdf.rb, line 37
37:       def initialize(io); @io = io; end

Public Instance methods

[Source]

    # File lib/rubidium/sdf.rb, line 39
39:       def all_field_names
40:         field_names = []
41:         each do |entry|
42:           field_names << entry.data_items.keys
43:         end
44:         field_names.flatten.uniq
45:       end

[Source]

    # File lib/rubidium/sdf.rb, line 47
47:       def each
48:         each_with_line_number do |entry, line_number|
49:           yield entry
50:         end
51:       end

[Source]

    # File lib/rubidium/sdf.rb, line 53
53:       def each_with_line_number
54:         io.rewind
55:         entry = Entry.new
56:         begin
57:           until io.eof? do
58:             line_number = io.lineno + 1
59:             entry[Entry::MOLFILE] = parse_molfile
60:             parse_data_items(entry)
61:             yield entry, line_number
62:             entry = Entry.new
63:           end
64:         rescue EOFError
65:           yield entry, io.lineno
66:         end
67:       end

[Validate]