Class: ChemScanner::Cdxml

Inherits:
ChemScanner::ChemDraw::Parser show all
Defined in:
lib/chem_scanner/cdxml.rb

Overview

Read and Parse CDXML

Constant Summary collapse

CDXML_DOCTYPE =
"http://www.cambridgesoft.com/xml/cdxml.dtd"

Instance Attribute Summary collapse

Attributes inherited from ChemScanner::ChemDraw::Parser

#bracket_map, #color_table, #font_table, #fragment_group_map, #fragment_map, #geometry_map, #graphic_map, #molecules, #reactions, #tempid, #text_map

Instance Method Summary collapse

Methods inherited from ChemScanner::ChemDraw::Parser

#fragment_as_line, #get_tempid, #n_atoms

Constructor Details

#initializeCdxml

Returns a new instance of Cdxml.



14
15
16
17
18
# File 'lib/chem_scanner/cdxml.rb', line 14

def initialize
  super

  @type = "cdxml"
end

Instance Attribute Details

#readerObject

Returns the value of attribute reader.



10
11
12
# File 'lib/chem_scanner/cdxml.rb', line 10

def reader
  @reader
end

#versionObject

Returns the value of attribute version.



10
11
12
# File 'lib/chem_scanner/cdxml.rb', line 10

def version
  @version
end

Instance Method Details

#raw_dataObject



43
44
45
# File 'lib/chem_scanner/cdxml.rb', line 43

def raw_data
  @cdxml.to_xml
end

#read(file, is_path = true) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/chem_scanner/cdxml.rb', line 20

def read(file, is_path = true)
  fs = is_path ? File.open(file) : file
  @cdxml = Nokogiri::XML(fs)
  return false if @cdxml.internal_subset.system_id != CDXML_DOCTYPE

  read_global

  @cdxml.xpath("//page").each do |page|
    @reader = page
    read_objects
  end

  rebuild_objects_map

  @scheme = Interpreter::Scheme.new(self)
  @scheme.interpret

  @molecules = @scheme.molecules
  @reactions = @scheme.reactions

  true
end

#read_globalObject



47
48
49
50
51
52
53
54
55
# File 'lib/chem_scanner/cdxml.rb', line 47

def read_global
  @version = @cdxml.xpath("//CDXML/@CreationProgram").text.split(" ").last

  ct = @cdxml.xpath("//CDXML/colortable").first
  @color_table = read_colortable(ct, "cdxml")

  ft = @cdxml.xpath("//CDXML/fonttable").first
  @font_table = read_fonttable(ft, "cdxml")
end

#read_objectsObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/chem_scanner/cdxml.rb', line 57

def read_objects
  nodes = @reader.element_children

  nodes.each do |node|
    @reader = node
    nid = (node.attr("id") || 0).to_i

    if ChemDraw::CDXML_OBJ[node.name] == "Group"
      read_objects
    else
      parse_object(node.name, nid)
    end
  end
end