Class: ChemScanner::Doc

Inherits:
Object
  • Object
show all
Defined in:
lib/chem_scanner/doc.rb

Overview

Read and Parse DOC

Direct Known Subclasses

Docx

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDoc

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_mapObject (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

#moleculesObject (readonly)

Returns the value of attribute molecules.



9
10
11
# File 'lib/chem_scanner/doc.rb', line 9

def molecules
  @molecules
end

#reactionsObject (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