Class: Chem::MSI::MSIReader
- Inherits:
-
Object
- Object
- Chem::MSI::MSIReader
- Defined in:
- lib/chem/db/msi.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input) ⇒ MSIReader
constructor
A new instance of MSIReader.
- #model ⇒ Object
- #read ⇒ Object
Constructor Details
#initialize(input) ⇒ MSIReader
Returns a new instance of MSIReader.
64 65 66 67 |
# File 'lib/chem/db/msi.rb', line 64 def initialize input @objects = {} @input = input end |
Class Method Details
.open(input) ⇒ Object
56 57 58 |
# File 'lib/chem/db/msi.rb', line 56 def MSIReader.open input MSIReader.new(input) end |
Instance Method Details
#model ⇒ Object
60 61 62 |
# File 'lib/chem/db/msi.rb', line 60 def model @top end |
#read ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/chem/db/msi.rb', line 69 def read current = MSIFile.new @top = current @input.each_line do |l| if /\((\d+) (\S+)/ =~ l case $2 when 'Model' current.child = Model.new($1) current = current.child when 'Atom' current.child = MSIAtom.new($1) current = current.child when 'Bond' current.child = MSIBond.new($1) current = current.child end @objects[$1.to_i] = current elsif /\(A (\S) (\S+) (.+)\)/ =~ (l) case $1 when 'C' current.prop[$2] = $3 when 'I' current.prop[$2] = $3.to_i when 'O' current.prop[$2] = @objects[$3.to_i] when 'D' current.prop[$2] = $3.scanf("(%f %f %f") end elsif /\s+\)/ =~ l current = current.parent end end end |