Class: OoxmlParser::Chart
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::Chart
- Defined in:
- lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb
Constant Summary
Constants inherited from OOXMLDocumentObject
OOXMLDocumentObject::DEFAULT_DIRECTORY_FOR_MEDIA
Instance Attribute Summary collapse
-
#alternate_content ⇒ Object
Returns the value of attribute alternate_content.
-
#axises ⇒ Object
Returns the value of attribute axises.
-
#data ⇒ Object
Returns the value of attribute data.
-
#display_labels ⇒ Object
Returns the value of attribute display_labels.
-
#grouping ⇒ Object
Returns the value of attribute grouping.
-
#legend ⇒ Object
Returns the value of attribute legend.
-
#shape_properties ⇒ Object
Returns the value of attribute shape_properties.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Chart
constructor
A new instance of Chart.
- #parse_properties(chart_prop_node) ⇒ Object
Methods inherited from OOXMLDocumentObject
#==, add_to_xmls_stack, copy_file_and_rename_to_zip, copy_media_file, current_xml, dir, encrypted_file?, get_link_from_rels, media_folder, option_enabled?, unzip_file
Constructor Details
#initialize ⇒ Chart
Returns a new instance of Chart.
13 14 15 16 17 18 19 20 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 13 def initialize @type = '' @data = [] @grouping = nil @title = nil @legend = nil @axises = [] end |
Instance Attribute Details
#alternate_content ⇒ Object
Returns the value of attribute alternate_content.
11 12 13 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11 def alternate_content @alternate_content end |
#axises ⇒ Object
Returns the value of attribute axises.
11 12 13 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11 def axises @axises end |
#data ⇒ Object
Returns the value of attribute data.
11 12 13 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11 def data @data end |
#display_labels ⇒ Object
Returns the value of attribute display_labels.
11 12 13 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11 def display_labels @display_labels end |
#grouping ⇒ Object
Returns the value of attribute grouping.
11 12 13 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11 def grouping @grouping end |
#legend ⇒ Object
Returns the value of attribute legend.
11 12 13 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11 def legend @legend end |
#shape_properties ⇒ Object
Returns the value of attribute shape_properties.
11 12 13 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11 def shape_properties @shape_properties end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11 def title @title end |
#type ⇒ Object
Returns the value of attribute type.
11 12 13 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 11 def type @type end |
Class Method Details
.parse ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 44 def self.parse chart = Chart.new chart_xml = Nokogiri::XML(File.open(OOXMLDocumentObject.current_xml)) chart_xml.xpath('c:chartSpace/*', 'xmlns:c' => 'http://schemas.openxmlformats.org/drawingml/2006/chart').each do |chart_space_node_child| case chart_space_node_child.name when 'AlternateContent' chart.alternate_content = AlternateContent.parse(chart_space_node_child) when 'spPr' chart.shape_properties = DocxShapeProperties.parse chart_space_node_child when 'chart' chart_space_node_child.xpath('*').each do |chart_node_child| case chart_node_child.name when 'plotArea' chart_node_child.xpath('*').each do |plot_area_node_child| next unless chart.type.empty? case plot_area_node_child.name when 'barChart' chart.type = :bar = plot_area_node_child.xpath('c:barDir') unless .first.nil? chart.type = :column if .first.attribute('val').value == 'col' end chart.parse_properties(plot_area_node_child) when 'lineChart' chart.type = :line chart.parse_properties(plot_area_node_child) when 'areaChart' chart.type = :area chart.parse_properties(plot_area_node_child) when 'bubbleChart' chart.type = :bubble chart.parse_properties(plot_area_node_child) when 'doughnutChart' chart.type = :doughnut chart.parse_properties(plot_area_node_child) when 'pieChart' chart.type = :pie chart.parse_properties(plot_area_node_child) when 'scatterChart' chart.type = :point chart.parse_properties(plot_area_node_child) when 'radarChart' chart.type = :radar chart.parse_properties(plot_area_node_child) when 'stockChart' chart.type = :stock chart.parse_properties(plot_area_node_child) when 'surface3DChart' chart.type = :surface_3d chart.parse_properties(plot_area_node_child) when 'line3DChart' chart.type = :line_3d chart.parse_properties(plot_area_node_child) when 'bar3DChart' chart.type = :bar_3d chart.parse_properties(plot_area_node_child) when 'pie3DChart' chart.type = :pie_3d chart.parse_properties(plot_area_node_child) end end chart_node_child.xpath('*').each do |plot_area_node_child| case plot_area_node_child.name when 'catAx' chart.axises << ChartAxis.parse(plot_area_node_child) when 'valAx' chart.axises << ChartAxis.parse(plot_area_node_child) end end when 'title' chart.title = ChartAxisTitle.parse(chart_node_child) when 'legend' chart.legend = ChartLegend.parse(chart_node_child) end end end end chart end |
Instance Method Details
#parse_properties(chart_prop_node) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb', line 22 def parse_properties(chart_prop_node) chart_prop_node.xpath('*').each do |chart_props_node_child| case chart_props_node_child.name when 'grouping' @grouping = chart_props_node_child.attribute('val').value.to_sym when 'ser' case @type when :bar, :line, :area, :pie, :doughnut, :radar, :stock, :surface_3d, :column val = chart_props_node_child.xpath('c:val')[0] when :point, :bubble val = chart_props_node_child.xpath('c:yVal')[0] else next end next if val.xpath('c:numRef').empty? @data << ChartCellsRange.parse(val.xpath('c:numRef').first).dup when 'dLbls' @display_labels = DisplayLabelsProperties.parse(chart_props_node_child) end end end |