Class: ChemScanner::ChemDraw::ColorTable
- Defined in:
- lib/chem_scanner/chem_draw/node/color_table.rb
Overview
ColorTable
Constant Summary
Constants included from BaseValue
BaseValue::ARROW_NOGO_CROSS, BaseValue::CDXML_ARROW_TYPE, BaseValue::CDXML_ATOM_EXTERNAL_CONNECTION_TYPE, BaseValue::CDXML_CDX_POINT, BaseValue::CDXML_GRAPHIC_TYPE, BaseValue::CDXML_LINE_TYPE, BaseValue::CDXML_NODE_TYPE, BaseValue::CDXML_ORBITAL_TYPE, BaseValue::CDXML_OVAL_TYPE, BaseValue::TEXT_ATTRIBUTES
Instance Attribute Summary collapse
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Attributes inherited from BaseNode
#id, #parser, #parser_type, #polygon
Instance Method Summary collapse
-
#initialize(parser_type, data) ⇒ ColorTable
constructor
A new instance of ColorTable.
- #read ⇒ Object
- #read_cdx ⇒ Object
- #read_cdxml ⇒ Object
Methods inherited from BaseNode
#assign_center, #bounding_box, #cdx_read, #cdxml_read, #center_x, #center_y, #get_tempid, #parse_node, #post_parse_node, #pre_parse_node, #set_cdx, #set_cdxml
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_type, data) ⇒ ColorTable
Returns a new instance of ColorTable.
7 8 9 10 |
# File 'lib/chem_scanner/chem_draw/node/color_table.rb', line 7 def initialize(parser_type, data) @parser_type = parser_type @data = data end |
Instance Attribute Details
#table ⇒ Object (readonly)
Returns the value of attribute table.
5 6 7 |
# File 'lib/chem_scanner/chem_draw/node/color_table.rb', line 5 def table @table end |
Instance Method Details
#read ⇒ Object
12 13 14 |
# File 'lib/chem_scanner/chem_draw/node/color_table.rb', line 12 def read @parser_type == "cdx" ? read_cdx : read_cdxml end |
#read_cdx ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/chem_scanner/chem_draw/node/color_table.rb', line 16 def read_cdx @nums = read_int(@data[0, 2], true) rgbs = binary_chunks(@data[2..-1], 2).map { |x| read_int(x, true) } table = rgbs.each_slice(3).to_a.map do |x| x.reduce("") do |memo, c| rgb = c >> 8 memo << rgb.to_s(16).rjust(2, "0") end end @table = %w[000000 FFFFFF] + table end |
#read_cdxml ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/chem_scanner/chem_draw/node/color_table.rb', line 30 def read_cdxml table = @data.element_children.each_with_object([]) do |color, t| next if color.name != "color" rgb = %w[r g b].reduce("") do |memo, c| ct = color.attr(c).to_i * 255 memo << ct.to_s(16).rjust(2, "0") end t.push(rgb) end @table = %w[000000 FFFFFF] + table end |