Class: ChemScanner::ChemDraw::BaseNode
- Inherits:
-
Object
- Object
- ChemScanner::ChemDraw::BaseNode
show all
- Includes:
- BaseValue
- Defined in:
- lib/chem_scanner/chem_draw/node/base_node.rb
Overview
Constant Summary
Constants included
from BaseValue
ChemScanner::ChemDraw::BaseValue::ARROW_NOGO_CROSS, ChemScanner::ChemDraw::BaseValue::CDXML_ARROW_TYPE, ChemScanner::ChemDraw::BaseValue::CDXML_ATOM_EXTERNAL_CONNECTION_TYPE, ChemScanner::ChemDraw::BaseValue::CDXML_CDX_POINT, ChemScanner::ChemDraw::BaseValue::CDXML_GRAPHIC_TYPE, ChemScanner::ChemDraw::BaseValue::CDXML_LINE_TYPE, ChemScanner::ChemDraw::BaseValue::CDXML_NODE_TYPE, ChemScanner::ChemDraw::BaseValue::CDXML_ORBITAL_TYPE, ChemScanner::ChemDraw::BaseValue::CDXML_OVAL_TYPE, ChemScanner::ChemDraw::BaseValue::TEXT_ATTRIBUTES
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from BaseValue
#binary_chunks, #cdx_styles, #cdx_text, #cdxml_text, #do_unhandled, #point_2d, #point_3d, #polygon_from_bb, #read_bounding_box, #read_ids, #read_int, #read_type, #read_value
Constructor Details
#initialize(parser, parser_type, id) ⇒ BaseNode
Returns a new instance of BaseNode.
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 12
def initialize(parser, parser_type, id)
@parser = parser
@parser_type = parser_type
check_id = id.nil? || id.zero?
@id = check_id ? @parser.get_tempid : id
case parser_type
when "cdx" then set_cdx
when "cdxml" then set_cdxml
end
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
10
11
12
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 10
def id
@id
end
|
#parser ⇒ Object
Returns the value of attribute parser.
10
11
12
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 10
def parser
@parser
end
|
#parser_type ⇒ Object
Returns the value of attribute parser_type.
10
11
12
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 10
def parser_type
@parser_type
end
|
#polygon ⇒ Object
Returns the value of attribute polygon.
10
11
12
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 10
def polygon
@polygon
end
|
Instance Method Details
#assign_center ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 92
def assign_center
return if @polygon.nil?
return unless @center.nil?
box = bounding_box
lb = box.leftbottom
rt = box.righttop
@center = Geometry::Point.new(
(lb.x + rt.x) / 2,
(lb.y + rt.y) / 2,
)
end
|
#bounding_box ⇒ Object
88
89
90
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 88
def bounding_box
@polygon.bounding_box
end
|
#cdx_read ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 41
def cdx_read
pre_parse_node
reader = @parser.reader
tag = reader.read_next
while tag.positive?
cid = reader.current_id
parse_node(tag, cid, reader.data)
tag = reader.read_next(false)
end
post_parse_node
end
|
#cdxml_read ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 57
def cdxml_read
pre_parse_node
nid = @parser.reader.attr("id").to_i
nid = nil if nid.zero?
@parser.reader.attributes.each_value do |attr|
parse_node(attr.name, nid, attr)
end
children = @parser.reader.element_children
children.each do |child|
@parser.reader = child
nid = @parser.reader.attr("id").to_i
nid = nid.to_i unless nid.nil?
parse_node(child.name, nid, child)
end
post_parse_node
end
|
#center_x ⇒ Object
106
107
108
109
110
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 106
def center_x
return nil if @center.nil?
center.x
end
|
#center_y ⇒ Object
112
113
114
115
116
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 112
def center_y
return nil if @center.nil?
center.y
end
|
#get_tempid ⇒ Object
118
119
120
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 118
def get_tempid
parser.get_tempid
end
|
#parse_node ⇒ Object
82
83
84
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 82
def parse_node
raise NotImplementedError, "You must implement the parse method"
end
|
#post_parse_node ⇒ Object
86
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 86
def post_parse_node; end
|
#pre_parse_node ⇒ Object
80
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 80
def pre_parse_node; end
|
#read ⇒ Object
35
36
37
38
39
|
# File 'lib/chem_scanner/chem_draw/node/base_node.rb', line 35
def read
return cdx_read if @parser_type == "cdx"
cdxml_read
end
|