ooxml_parser 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +17 -1
  3. data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/chart_style.rb +4 -0
  4. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +1 -0
  5. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_axis.rb +9 -0
  6. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_axis/scaling.rb +20 -0
  7. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb +1 -1
  8. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb +3 -2
  9. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_body_properties/ooxml_shape_body_properties.rb +8 -0
  10. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties/text_box.rb +1 -1
  11. data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +2 -2
  12. data/lib/ooxml_parser/common_parser/common_data/color.rb +11 -20
  13. data/lib/ooxml_parser/common_parser/common_data/color/color_helper.rb +1 -1
  14. data/lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb +57 -0
  15. data/lib/ooxml_parser/common_parser/common_data/colors/theme_colors.rb +3 -6
  16. data/lib/ooxml_parser/common_parser/common_data/coordinates.rb +17 -1
  17. data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +12 -1
  18. data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +4 -4
  19. data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object/ooxml_document_object_helper.rb +30 -1
  20. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb +5 -2
  21. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb +9 -1
  22. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +1 -1
  23. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/text.rb +23 -0
  24. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_borders.rb +2 -2
  25. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb +0 -1
  26. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/tabs.rb +2 -2
  27. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/{tab_list/presentation_tab.rb → tabs/tab.rb} +17 -4
  28. data/lib/ooxml_parser/common_parser/common_data/table.rb +1 -1
  29. data/lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb +1 -3
  30. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style.rb +31 -37
  31. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties.rb +4 -0
  32. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties/table_style_properties_helper.rb +2 -2
  33. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell.rb +4 -4
  34. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/border.rb +1 -1
  35. data/lib/ooxml_parser/common_parser/common_data/table/table_properties.rb +1 -16
  36. data/lib/ooxml_parser/docx_parser/docx_data/document_structure.rb +14 -7
  37. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comment.rb +2 -2
  38. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comments_extended.rb +39 -0
  39. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comments_extended/comment_extended.rb +24 -0
  40. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb +9 -12
  41. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb +1 -1
  42. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph.rb +51 -73
  43. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/delimeter.rb +2 -2
  44. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_helper.rb +8 -0
  45. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb +8 -56
  46. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb +2 -12
  47. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/inserted.rb +15 -1
  48. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb +30 -0
  49. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_properties.rb +28 -0
  50. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/structured_document_tag.rb +26 -0
  51. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb +1 -1
  52. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb +10 -10
  53. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_margins.rb +9 -16
  54. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb +11 -9
  55. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation.rb +5 -2
  56. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme/theme_color.rb +1 -3
  57. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb +35 -24
  58. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/common_slide_data.rb +26 -0
  59. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/common_slide_data/shape_tree.rb +33 -0
  60. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/connection_shape.rb +5 -0
  61. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/graphic_frame/graphic_frame.rb +2 -0
  62. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/presentation_notes.rb +21 -0
  63. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/shapes_grouping.rb +2 -0
  64. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb +3 -3
  65. data/lib/ooxml_parser/version.rb +1 -1
  66. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +1 -1
  67. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill.rb +20 -0
  68. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill/pattern_fill.rb +2 -2
  69. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb +5 -1
  70. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +10 -1
  71. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/ole_objects.rb +18 -0
  72. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view.rb +1 -1
  73. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part.rb +7 -1
  74. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/autofilter.rb +34 -0
  75. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/autofilter/filter_column.rb +28 -0
  76. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension.rb +5 -0
  77. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/sparkline_groups.rb +31 -0
  78. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/sparkline_groups/sparkline_group.rb +113 -0
  79. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/table_style_info.rb +41 -0
  80. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing.rb +5 -11
  81. metadata +31 -14
  82. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/tab_list.rb +0 -36
  83. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/tabs/paragraph_tab.rb +0 -26
@@ -0,0 +1,33 @@
1
+ module OoxmlParser
2
+ # Class for parsing `spTree` tag
3
+ class ShapeTree < OOXMLDocumentObject
4
+ # @return [Array] elements of shape tree
5
+ attr_reader :elements
6
+
7
+ def initialize(parent: nil)
8
+ @elements = []
9
+ @parent = parent
10
+ end
11
+
12
+ # Parse ShapeTree object
13
+ # @param node [Nokogiri::XML:Element] node to parse
14
+ # @return [ShapeTree] result of parsing
15
+ def parse(node)
16
+ node.xpath('*').each do |node_child|
17
+ case node_child.name
18
+ when 'sp'
19
+ @elements << DocxShape.new(parent: self).parse(node_child).dup
20
+ when 'pic'
21
+ @elements << DocxPicture.new(parent: self).parse(node_child)
22
+ when 'graphicFrame'
23
+ @elements << GraphicFrame.new(parent: self).parse(node_child)
24
+ when 'grpSp'
25
+ @elements << ShapesGrouping.new(parent: self).parse(node_child)
26
+ when 'cxnSp'
27
+ @elements << ConnectionShape.new(parent: self).parse(node_child)
28
+ end
29
+ end
30
+ self
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ module OoxmlParser
2
+ # Class for storing `cxnSp` data
3
+ class ConnectionShape < DocxShape
4
+ end
5
+ end
@@ -30,6 +30,8 @@ module OoxmlParser
30
30
  OOXMLDocumentObject.add_to_xmls_stack(OOXMLDocumentObject.get_link_from_rels(graphic_node_child.attribute('id').value))
31
31
  graphic_data << Chart.parse
32
32
  OOXMLDocumentObject.xmls_stack.pop
33
+ when 'oleObj'
34
+ graphic_data << OleObject.new(parent: self).parse(graphic_node_child)
33
35
  end
34
36
  end
35
37
  end
@@ -0,0 +1,21 @@
1
+ module OoxmlParser
2
+ # Class for p:notes
3
+ class PresentationNotes < OOXMLDocumentObject
4
+ # @return [CommonSlideData] common slide data
5
+ attr_reader :common_slide_data
6
+
7
+ # Parse PresentationNotes object
8
+ # @param file [String] file to parse
9
+ # @return [PresentationNotes] result of parsing
10
+ def parse(file)
11
+ node = Nokogiri::XML(File.open(file))
12
+ node.xpath('p:notes/*').each do |node_child|
13
+ case node_child.name
14
+ when 'cSld'
15
+ @common_slide_data = CommonSlideData.new(parent: self).parse(node_child)
16
+ end
17
+ end
18
+ self
19
+ end
20
+ end
21
+ end
@@ -14,6 +14,8 @@ module OoxmlParser
14
14
  def parse(node)
15
15
  node.xpath('*').each do |child_node|
16
16
  case child_node.name
17
+ when 'cxnSp'
18
+ @elements << ConnectionShape.new(parent: self).parse(child_node)
17
19
  when 'grpSpPr'
18
20
  @properties = DocxShapeProperties.new(parent: self).parse(child_node)
19
21
  when 'pic'
@@ -2,11 +2,11 @@ module OoxmlParser
2
2
  # Methods to help working with slide data
3
3
  module SlideHelper
4
4
  def nonempty_elements
5
- @elements.select { |cur_shape| !cur_shape.text_body.paragraphs.first.characters.empty? }
5
+ elements.reject { |cur_shape| cur_shape.text_body.paragraphs.first.characters.empty? }
6
6
  end
7
7
 
8
8
  def graphic_frames
9
- @elements.select { |cur_element| cur_element.is_a?(GraphicFrame) }
9
+ elements.select { |cur_element| cur_element.is_a?(GraphicFrame) }
10
10
  end
11
11
 
12
12
  # Get transform property of object, by object type
@@ -44,7 +44,7 @@ module OoxmlParser
44
44
  end
45
45
 
46
46
  def content_distribute(object, slide_size)
47
- return [:horizontally, :vertically] if content_horizontal_align(object, slide_size) == :center && content_vertical_align(object, slide_size) == :middle
47
+ return %i[horizontally vertically] if content_horizontal_align(object, slide_size) == :center && content_vertical_align(object, slide_size) == :middle
48
48
  return [:horizontally] if content_horizontal_align(object, slide_size) == :center
49
49
  return [:vertically] if content_vertical_align(object, slide_size) == :middle
50
50
  end
@@ -1,6 +1,6 @@
1
1
  module OoxmlParser
2
2
  # This module holds the RuboCop version information.
3
3
  module Version
4
- STRING = '0.2.0'.freeze
4
+ STRING = '0.3.0'.freeze
5
5
  end
6
6
  end
@@ -98,7 +98,7 @@ module OoxmlParser
98
98
 
99
99
  class << self
100
100
  # @return [Array, Nokogiri::XML::Eelement] list of shared strings
101
- attr_accessor :shared_strings
101
+ attr_writer :shared_strings
102
102
  attr_accessor :styles_node
103
103
 
104
104
  # Accessor for shared string. Initialization for this array
@@ -4,11 +4,31 @@ module OoxmlParser
4
4
  class Fill < OOXMLDocumentObject
5
5
  # @return [PatternFill] pattern fill
6
6
  attr_accessor :pattern_fill
7
+ # @return [Color] second color
8
+ attr_reader :color2
9
+ # @return [String] id of file
10
+ attr_reader :id
11
+ # @return [FileReference] file of fill
12
+ attr_reader :file
13
+ # @return [Symbol] value
14
+ attr_reader :value
7
15
 
8
16
  # Parse Fill data
9
17
  # @param [Nokogiri::XML:Element] node with Fill data
10
18
  # @return [Fill] value of Fill data
11
19
  def parse(node)
20
+ node.attributes.each do |key, value|
21
+ case key
22
+ when 'color2'
23
+ @color2 = Color.new(parent: self).parse_hex_string(value.value.split(' ').first.delete('#'))
24
+ when 'id'
25
+ @id = value.value.to_s
26
+ @file = FileReference.new(parent: self).parse(node)
27
+ when 'type'
28
+ @type = value_to_symbol(value)
29
+ end
30
+ end
31
+
12
32
  node.xpath('*').each do |node_child|
13
33
  case node_child.name
14
34
  when 'patternFill'
@@ -22,9 +22,9 @@ module OoxmlParser
22
22
  node.xpath('*').each do |node_child|
23
23
  case node_child.name
24
24
  when 'fgColor'
25
- @foreground_color = Color.parse_color_tag(node_child)
25
+ @foreground_color = OoxmlColor.new(parent: self).parse(node_child)
26
26
  when 'bgColor'
27
- @background_color = Color.parse_color_tag(node_child)
27
+ @background_color = OoxmlColor.new(parent: self).parse(node_child)
28
28
  end
29
29
  end
30
30
  self
@@ -2,6 +2,8 @@ module OoxmlParser
2
2
  # Parsing `fonts` tag
3
3
  class Font < OOXMLDocumentObject
4
4
  attr_accessor :name, :size, :font_style, :color
5
+ # @return [ValuedChild] vertical alignment of font
6
+ attr_reader :vertical_alignment
5
7
 
6
8
  def initialize(parent: nil)
7
9
  @name = 'Calibri'
@@ -26,7 +28,9 @@ module OoxmlParser
26
28
  when 'u'
27
29
  @font_style.underlined = Underline.new(:single)
28
30
  when 'color'
29
- @color = Color.parse_color_tag(node_child)
31
+ @color = OoxmlColor.new(parent: self).parse(node_child)
32
+ when 'vertAlign'
33
+ @vertical_alignment = ValuedChild.new(:symbol, parent: self).parse(node_child)
30
34
  end
31
35
  end
32
36
  self
@@ -1,4 +1,5 @@
1
1
  require_relative 'worksheet/excel_comments'
2
+ require_relative 'worksheet/ole_objects'
2
3
  require_relative 'worksheet/sheet_format_properties'
3
4
  require_relative 'worksheet/sheet_view'
4
5
  require_relative 'worksheet/table_part'
@@ -14,6 +15,10 @@ module OoxmlParser
14
15
  attr_accessor :xml_name
15
16
  # @return [Relationships] array of relationships
16
17
  attr_accessor :relationships
18
+ # @return [Relationships] array of ole objects
19
+ attr_accessor :ole_objects
20
+ # @return [ExtensionList] list of extensions
21
+ attr_accessor :extension_list
17
22
 
18
23
  def initialize
19
24
  @columns = []
@@ -88,7 +93,7 @@ module OoxmlParser
88
93
  when 'cols'
89
94
  worksheet.columns = XlsxColumnProperties.parse_list(worksheet_node_child, parent: worksheet)
90
95
  when 'autoFilter'
91
- worksheet.autofilter = Coordinates.parser_coordinates_range(worksheet_node_child.attribute('ref').value.to_s)
96
+ worksheet.autofilter = Autofilter.new(parent: self).parse(worksheet_node_child)
92
97
  when 'tableParts'
93
98
  worksheet_node_child.xpath('*').each do |part_node|
94
99
  worksheet.table_parts << TablePart.new(parent: worksheet).parse(part_node)
@@ -97,6 +102,10 @@ module OoxmlParser
97
102
  worksheet_node_child.xpath('*').each do |view_child|
98
103
  worksheet.sheet_views << SheetView.new(parent: worksheet).parse(view_child)
99
104
  end
105
+ when 'oleObjects'
106
+ worksheet.ole_objects = OleObjects.new(parent: worksheet).parse(worksheet_node_child)
107
+ when 'extLst'
108
+ worksheet.extension_list = ExtensionList.new(parent: self).parse(worksheet_node_child)
100
109
  end
101
110
  end
102
111
  worksheet.comments = ExcelComments.parse_file(File.basename(path_to_xml_file), OOXMLDocumentObject.path_to_folder)
@@ -0,0 +1,18 @@
1
+ module OoxmlParser
2
+ # Class for parsing `oleObjects`
3
+ class OleObjects < OOXMLDocumentObject
4
+ # Parse OleObjects object
5
+ # @param node [Nokogiri::XML:Element] node to parse
6
+ # @return [Array] list of OleObjects
7
+ def parse(node)
8
+ list = []
9
+ node.xpath('*').each do |node_child|
10
+ case node_child.name
11
+ when 'AlternateContent'
12
+ list << AlternateContent.new(parent: self).parse(node_child)
13
+ end
14
+ end
15
+ list
16
+ end
17
+ end
18
+ end
@@ -18,7 +18,7 @@ module OoxmlParser
18
18
  # @param node [Nokogiri::XML:Element] node to parse
19
19
  # @return [SheetView] result of parsing
20
20
  def parse(node)
21
- node.attributes.each do |key, _value|
21
+ node.attributes.each_key do |key|
22
22
  case key
23
23
  when 'showGridLines'
24
24
  @show_gridlines = attribute_enabled?(node, key)
@@ -1,10 +1,14 @@
1
+ require_relative 'table_part/autofilter'
1
2
  require_relative 'table_part/extension_list'
3
+ require_relative 'table_part/table_style_info'
2
4
  module OoxmlParser
3
5
  # Class for `tablePart` data
4
6
  class TablePart < OOXMLDocumentObject
5
7
  attr_accessor :name, :display_name, :reference, :autofilter, :columns
6
8
  # @return [ExtensionList] list of extensions
7
9
  attr_accessor :extension_list
10
+ # @return [TableStyleInfo] describe style of table
11
+ attr_accessor :table_style_info
8
12
 
9
13
  # Parse TablePart object
10
14
  # @param node [Nokogiri::XML:Element] node to parse
@@ -26,9 +30,11 @@ module OoxmlParser
26
30
  table_node.xpath('*').each do |node_child|
27
31
  case node_child.name
28
32
  when 'autoFilter'
29
- @autofilter = Coordinates.parser_coordinates_range node_child.attribute('ref').value
33
+ @autofilter = Autofilter.new(parent: self).parse(node_child)
30
34
  when 'extLst'
31
35
  @extension_list = ExtensionList.new(parent: self).parse(node_child)
36
+ when 'tableStyleInfo'
37
+ @table_style_info = TableStyleInfo.new(parent: self).parse(node_child)
32
38
  end
33
39
  end
34
40
  self
@@ -0,0 +1,34 @@
1
+ require_relative 'autofilter/filter_column'
2
+ module OoxmlParser
3
+ # Class for `autoFilter` data
4
+ # AutoFilter temporarily hides rows based on a
5
+ # filter criteria, which is applied column by column
6
+ # to a table of data in the worksheet.
7
+ # This collection expresses AutoFilter settings.
8
+ class Autofilter < OOXMLDocumentObject
9
+ # @return [Coordinates] Reference to the cell range to which the AutoFilter is applied.
10
+ attr_accessor :ref
11
+ # @return [FilterColumn] data of filter column
12
+ attr_accessor :filter_column
13
+
14
+ # Parse Autofilter data
15
+ # @param [Nokogiri::XML:Element] node with Autofilter data
16
+ # @return [Autofilter] value of Autofilter data
17
+ def parse(node)
18
+ node.attributes.each do |key, value|
19
+ case key
20
+ when 'ref'
21
+ @ref = Coordinates.parser_coordinates_range(value.value)
22
+ end
23
+ end
24
+
25
+ node.xpath('*').each do |node_child|
26
+ case node_child.name
27
+ when 'filterColumn'
28
+ @filter_column = FilterColumn.new(parent: self).parse(node_child)
29
+ end
30
+ end
31
+ self
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,28 @@
1
+ module OoxmlParser
2
+ # Class for `filterColumn` data
3
+ # The filterColumn collection identifies a particular
4
+ # column in the AutoFilter range and specifies
5
+ # filter information that has been applied to this column.
6
+ class FilterColumn < OOXMLDocumentObject
7
+ # @return [True, False] Flag indicating whether the filter button is visible.
8
+ attr_accessor :show_button
9
+
10
+ def initialize(parent: nil)
11
+ @show_button = true
12
+ @parent = parent
13
+ end
14
+
15
+ # Parse FilterColumn data
16
+ # @param [Nokogiri::XML:Element] node with FilterColumn data
17
+ # @return [FilterColumn] value of FilterColumn data
18
+ def parse(node)
19
+ node.attributes.each do |key, value|
20
+ case key
21
+ when 'showButton'
22
+ @show_button = attribute_enabled?(value)
23
+ end
24
+ end
25
+ self
26
+ end
27
+ end
28
+ end
@@ -1,9 +1,12 @@
1
+ require_relative 'extension/sparkline_groups'
1
2
  require_relative 'extension/x14_table'
2
3
  module OoxmlParser
3
4
  # Class for `ext` data
4
5
  class Extension < OOXMLDocumentObject
5
6
  # @return [X14Table] table data in x14 namespace
6
7
  attr_accessor :table
8
+ # @return [SparklineGroups] list of groups
9
+ attr_reader :sparkline_groups
7
10
 
8
11
  # Parse Extension data
9
12
  # @param [Nokogiri::XML:Element] node with Extension data
@@ -13,6 +16,8 @@ module OoxmlParser
13
16
  case column_node.name
14
17
  when 'table'
15
18
  @table = X14Table.new(parent: self).parse(column_node)
19
+ when 'sparklineGroups'
20
+ @sparkline_groups = SparklineGroups.new(parent: self).parse(column_node)
16
21
  end
17
22
  end
18
23
  self
@@ -0,0 +1,31 @@
1
+ require_relative 'sparkline_groups/sparkline_group'
2
+ module OoxmlParser
3
+ # Class for `sparklineGroups` data
4
+ class SparklineGroups < OOXMLDocumentObject
5
+ # @return [Array<SparklineGroup>] list of sparkline group
6
+ attr_reader :sparklines_groups
7
+
8
+ def initialize(parent: nil)
9
+ @sparklines_groups = []
10
+ @parent = parent
11
+ end
12
+
13
+ # @return [Array, SparklineGroups] accessor
14
+ def [](key)
15
+ sparklines_groups[key]
16
+ end
17
+
18
+ # Parse SparklineGroups data
19
+ # @param [Nokogiri::XML:Element] node with SparklineGroups data
20
+ # @return [SparklineGroups] value of SparklineGroups data
21
+ def parse(node)
22
+ node.xpath('*').each do |column_node|
23
+ case column_node.name
24
+ when 'sparklineGroup'
25
+ @sparklines_groups << SparklineGroup.new(parent: self).parse(column_node)
26
+ end
27
+ end
28
+ self
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,113 @@
1
+ module OoxmlParser
2
+ # Class for `sparklineGroup` data
3
+ class SparklineGroup < OOXMLDocumentObject
4
+ # @return [Symbol] display empty cells as
5
+ attr_reader :display_empty_cells_as
6
+ # @return [True, False] display empty cells as
7
+ attr_reader :display_hidden
8
+ # @return [True, False] display x axis
9
+ attr_reader :display_x_axis
10
+ # @return [True, False] right to left
11
+ attr_reader :right_to_left
12
+ # @return [True, False] minimal axis type
13
+ attr_reader :min_axis_type
14
+ # @return [True, False] maximal axis type
15
+ attr_reader :max_axis_type
16
+ # @return [Float] manual minimum value
17
+ attr_reader :manual_min
18
+ # @return [[Float] manual maximum value
19
+ attr_reader :manual_max
20
+ # @return [Symbol] type of group
21
+ attr_reader :type
22
+ # @return [OoxmlSize] line weight
23
+ attr_reader :line_weight
24
+ # @return [True, False] show high point
25
+ attr_reader :high_point
26
+ # @return [True, False] show low point
27
+ attr_reader :low_point
28
+ # @return [True, False] show first point
29
+ attr_reader :first_point
30
+ # @return [True, False] show last point
31
+ attr_reader :last_point
32
+ # @return [True, False] show negative point
33
+ attr_reader :negative_point
34
+ # @return [True, False] show markers
35
+ attr_reader :markers
36
+ # @return [OoxmlColor] color of series
37
+ attr_reader :color_series
38
+ # @return [OoxmlColor] high points color
39
+ attr_reader :color_high
40
+ # @return [OoxmlColor] low points color
41
+ attr_reader :color_low
42
+ # @return [OoxmlColor] first points color
43
+ attr_reader :color_first
44
+ # @return [OoxmlColor] last points color
45
+ attr_reader :color_last
46
+ # @return [OoxmlColor] negative points color
47
+ attr_reader :color_negative
48
+ # @return [OoxmlColor] markers color
49
+ attr_reader :color_markers
50
+
51
+ # Parse SparklineGroup
52
+ # @param [Nokogiri::XML:Node] node with SparklineGroup
53
+ # @return [SparklineGroup] result of parsing
54
+ def parse(node)
55
+ node.attributes.each do |key, value|
56
+ case key
57
+ when 'type'
58
+ @type = value_to_symbol(value)
59
+ when 'displayEmptyCellsAs'
60
+ @display_empty_cells_as = value_to_symbol(value)
61
+ when 'displayHidden'
62
+ @display_hidden = attribute_enabled?(value)
63
+ when 'displayXAxis'
64
+ @display_x_axis = attribute_enabled?(value)
65
+ when 'rightToLeft'
66
+ @right_to_left = attribute_enabled?(value)
67
+ when 'minAxisType'
68
+ @min_axis_type = value_to_symbol(value)
69
+ when 'maxAxisType'
70
+ @max_axis_type = value_to_symbol(value)
71
+ when 'manualMin'
72
+ @manual_min = value.value.to_f
73
+ when 'manualMax'
74
+ @manual_max = value.value.to_f
75
+ when 'lineWeight'
76
+ @line_weight = OoxmlSize.new(value.value.to_f, :point)
77
+ when 'high'
78
+ @high_point = attribute_enabled?(value)
79
+ when 'low'
80
+ @low_point = attribute_enabled?(value)
81
+ when 'first'
82
+ @first_point = attribute_enabled?(value)
83
+ when 'last'
84
+ @last_point = attribute_enabled?(value)
85
+ when 'negative'
86
+ @negative_point = attribute_enabled?(value)
87
+ when 'markers'
88
+ @markers = attribute_enabled?(value)
89
+ end
90
+ end
91
+
92
+ node.xpath('*').each do |node_child|
93
+ case node_child.name
94
+ when 'colorSeries'
95
+ @color_series = OoxmlColor.new(parent: self).parse(node_child)
96
+ when 'colorHigh'
97
+ @color_high = OoxmlColor.new(parent: self).parse(node_child)
98
+ when 'colorLow'
99
+ @color_low = OoxmlColor.new(parent: self).parse(node_child)
100
+ when 'colorFirst'
101
+ @color_first = OoxmlColor.new(parent: self).parse(node_child)
102
+ when 'colorLast'
103
+ @color_last = OoxmlColor.new(parent: self).parse(node_child)
104
+ when 'colorNegative'
105
+ @color_negative = OoxmlColor.new(parent: self).parse(node_child)
106
+ when 'colorMarkers'
107
+ @color_markers = OoxmlColor.new(parent: self).parse(node_child)
108
+ end
109
+ end
110
+ self
111
+ end
112
+ end
113
+ end