Class: Chem::MDL::SdfParser
- Inherits:
-
Object
- Object
- Chem::MDL::SdfParser
- Includes:
- Enumerable
- Defined in:
- lib/chem/db/sdf.rb
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(file) ⇒ SdfParser
constructor
A new instance of SdfParser.
Constructor Details
#initialize(file) ⇒ SdfParser
10 11 12 13 |
# File 'lib/chem/db/sdf.rb', line 10 def initialize file require 'chem/db/mdl' @input = open(file) end |
Class Method Details
.parse(file) ⇒ Object
30 31 32 |
# File 'lib/chem/db/sdf.rb', line 30 def self.parse file SdfParser.new(file) end |
Instance Method Details
#each ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/chem/db/sdf.rb', line 15 def each @input.rewind # for \r\n and \n first_entry = true from = 0 @input.each("$$$$") do |entry| from = entry.index("\n") + 1unless first_entry first_entry = false next if entry[from..-1].length < 3 yield MdlMolecule.parse_io(StringIO.new(entry[from..-1])) end end |