Class: ChemScanner::Doc
- Inherits:
-
Object
- Object
- ChemScanner::Doc
- Defined in:
- lib/chem_scanner/doc.rb
Overview
Read and Parse DOC
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cdx_map ⇒ Object
readonly
Returns the value of attribute cdx_map.
-
#molecules ⇒ Object
readonly
Returns the value of attribute molecules.
-
#reactions ⇒ Object
readonly
Returns the value of attribute reactions.
Instance Method Summary collapse
- #extract_cdx_data(path) ⇒ Object
-
#initialize ⇒ Doc
constructor
A new instance of Doc.
- #read(path) ⇒ Object
- #to_cml(molecule_only = false) ⇒ Object
Constructor Details
#initialize ⇒ Doc
Returns a new instance of Doc.
11 12 13 14 15 |
# File 'lib/chem_scanner/doc.rb', line 11 def initialize @reactions = [] @molecules = [] @cdx_map = {} end |
Instance Attribute Details
#cdx_map ⇒ Object (readonly)
Returns the value of attribute cdx_map.
9 10 11 |
# File 'lib/chem_scanner/doc.rb', line 9 def cdx_map @cdx_map end |
#molecules ⇒ Object (readonly)
Returns the value of attribute molecules.
9 10 11 |
# File 'lib/chem_scanner/doc.rb', line 9 def molecules @molecules end |
#reactions ⇒ Object (readonly)
Returns the value of attribute reactions.
9 10 11 |
# File 'lib/chem_scanner/doc.rb', line 9 def reactions @reactions end |
Instance Method Details
#extract_cdx_data(path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chem_scanner/doc.rb', line 33 def extract_cdx_data(path) ole = Ole::Storage.open(path).root["ObjectPool"] cdx_arr = [] ole.children.each do |obj| contents = obj["CONTENTS"] next if contents.nil? content_data = contents.read next unless content_data[0, 8] == "VjCD0100" cdx_arr.push(content_data) end cdx_arr end |
#read(path) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/chem_scanner/doc.rb', line 17 def read(path) extract_cdx_data(path).each do |cdx_content| cdx = Cdx.new cdx.read(cdx_content, false) @molecules.concat(cdx.molecules) @reactions.concat(cdx.reactions) length = cdx_content.length uuid = "#{length}#{reactions.count}#{molecules.count}" @cdx_map[uuid] = cdx end true end |
#to_cml(molecule_only = false) ⇒ Object
50 51 52 53 54 |
# File 'lib/chem_scanner/doc.rb', line 50 def to_cml(molecule_only = false) objs = molecule_only ? @molecules : @reactions cml = ChemScanner::Export::CML.new(objs, molecule_only) cml.process end |