ooxml_parser 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -2,11 +2,12 @@ require_relative 'paragrpah_properties/numbering_properties'
2
2
  require_relative 'paragrpah_properties/paragraph_borders'
3
3
  require_relative 'paragrpah_properties/paragraph_spacing'
4
4
  require_relative 'paragrpah_properties/spacing'
5
- require_relative 'paragrpah_properties/tab_list'
6
5
  require_relative 'paragrpah_properties/tabs'
7
6
  module OoxmlParser
8
7
  class ParagraphProperties < OOXMLDocumentObject
9
8
  attr_accessor :align, :numbering, :level, :spacing, :spacing_before, :spacing_after, :indent, :margin_left, :margin_right
9
+ # @return [FrameProperties] frame properties
10
+ attr_reader :frame_properties
10
11
  # @return [Tabs] list of tabs
11
12
  attr_accessor :tabs
12
13
  # @return [RunProperties] properties of run
@@ -68,10 +69,12 @@ module OoxmlParser
68
69
  when 'buAutoNum'
69
70
  @numbering.type = node_child.attribute('type').value.to_sym
70
71
  @numbering.start_at = node_child.attribute('startAt').value if node_child.attribute('startAt')
72
+ when 'framePr'
73
+ @frame_properties = FrameProperties.new(parent: self).parse(node_child)
71
74
  when 'tabs'
72
75
  @tabs = Tabs.new(parent: self).parse(node_child)
73
76
  when 'tabLst'
74
- @tabs = TabList.new(parent: self).parse(node_child)
77
+ @tabs = Tabs.new(parent: self).parse(node_child)
75
78
  when 'ind'
76
79
  @indent = Indents.new(parent: self).parse(node_child)
77
80
  when 'rPr'
@@ -1,8 +1,13 @@
1
1
  require_relative 'paragraph_run/run_properties'
2
+ require_relative 'paragraph_run/text'
2
3
  module OoxmlParser
3
4
  # Class for parsing `r` tags
4
5
  class ParagraphRun < OOXMLDocumentObject
5
6
  attr_accessor :properties, :text
7
+ # @return [Text] text of run
8
+ attr_reader :t
9
+ # @return [Tab] tab of paragraph
10
+ attr_reader :tab
6
11
 
7
12
  def initialize(properties = RunProperties.new, text = '', parent: nil)
8
13
  @properties = properties
@@ -19,7 +24,10 @@ module OoxmlParser
19
24
  when 'rPr'
20
25
  @properties = RunProperties.new(parent: self).parse(node_child)
21
26
  when 't'
22
- @text = node_child.text
27
+ @t = Text.new(parent: self).parse(node_child)
28
+ @text = t.text
29
+ when 'tab'
30
+ @tab = Tab.new(parent: self).parse(node_child)
23
31
  end
24
32
  end
25
33
  self
@@ -89,7 +89,7 @@ module OoxmlParser
89
89
  when 'spacing'
90
90
  @spacing = RunSpacing.new(parent: self).parse(node_child)
91
91
  when 'color'
92
- @color = Color.parse_color_tag(node_child)
92
+ @color = OoxmlColor.new(parent: self).parse(node_child)
93
93
  when 'solidFill'
94
94
  @font_color = Color.parse_color(node_child.xpath('*').first)
95
95
  when 'latin'
@@ -0,0 +1,23 @@
1
+ module OoxmlParser
2
+ # Class for parsing `t` tags
3
+ class Text < OOXMLDocumentObject
4
+ # @return [Symbol] space values
5
+ attr_reader :space
6
+ # @return [String] text value
7
+ attr_reader :text
8
+
9
+ # Parse Text object
10
+ # @param node [Nokogiri::XML:Element] node to parse
11
+ # @return [Text] result of parsing
12
+ def parse(node)
13
+ @text = node.text
14
+ node.attributes.each do |key, value|
15
+ case key
16
+ when 'space'
17
+ @space = value_to_symbol(value)
18
+ end
19
+ end
20
+ self
21
+ end
22
+ end
23
+ end
@@ -22,8 +22,8 @@ module OoxmlParser
22
22
  result << :bottom if @bottom.val == :single
23
23
  result << :inner if @between.val == :single
24
24
  return :none if result == []
25
- return :all if result == [:left, :right, :top, :bottom, :inner]
26
- return :outer if result == [:left, :right, :top, :bottom]
25
+ return :all if result == %i[left right top bottom inner]
26
+ return :outer if result == %i[left right top bottom]
27
27
  result.first if result.size == 1
28
28
  end
29
29
 
@@ -1,4 +1,3 @@
1
- # endcoding: utf-8
2
1
  # @author Pavel.Lobashov
3
2
 
4
3
  # Class to describe spacing
@@ -1,4 +1,4 @@
1
- require_relative 'tabs/paragraph_tab'
1
+ require_relative 'tabs/tab'
2
2
  module OoxmlParser
3
3
  # Class for working with `w:tabs`
4
4
  class Tabs < OOXMLDocumentObject
@@ -27,7 +27,7 @@ module OoxmlParser
27
27
  node.xpath('*').each do |node_child|
28
28
  case node_child.name
29
29
  when 'tab'
30
- @tabs_array << ParagraphTab.new(parent: self).parse(node_child)
30
+ @tabs_array << Tab.new(parent: self).parse(node_child)
31
31
  end
32
32
  end
33
33
  self
@@ -1,8 +1,10 @@
1
1
  module OoxmlParser
2
- # Class for storing `a:tab` data
3
- class PresentationTab < OOXMLDocumentObject
2
+ # Class for storing `w:tab`, `a:tab` data
3
+ class Tab < OOXMLDocumentObject
4
4
  # @return [Symbol] Specifies the style of the tab.
5
5
  attr_accessor :value
6
+ # @return [Symbol] Specifies the leader symbol of tab
7
+ attr_reader :leader
6
8
  # @return [OOxmlSize] Specifies the position of the tab stop.
7
9
  attr_accessor :position
8
10
 
@@ -14,13 +16,24 @@ module OoxmlParser
14
16
  def parse(node)
15
17
  node.attributes.each do |key, value|
16
18
  case key
17
- when 'algn'
19
+ when 'algn', 'val'
18
20
  @value = value_to_symbol(value)
21
+ when 'leader'
22
+ @leader = value_to_symbol(value)
19
23
  when 'pos'
20
- @position = OoxmlSize.new(value.value.to_f, :emu)
24
+ @position = OoxmlSize.new(value.value.to_f, position_unit(node))
21
25
  end
22
26
  end
23
27
  self
24
28
  end
29
+
30
+ private
31
+
32
+ # @param node [Nokogiri::XML:Element] node to determine size
33
+ # @return [Symbol] type of size unit
34
+ def position_unit(node)
35
+ return :emu if node.namespace.prefix == 'a'
36
+ :dxa
37
+ end
25
38
  end
26
39
  end
@@ -28,7 +28,7 @@ module OoxmlParser
28
28
  def parse(node,
29
29
  number = 0,
30
30
  default_table_properties = TableProperties.new)
31
- table_properties = default_table_properties.copy
31
+ table_properties = default_table_properties.dup
32
32
  table_properties.jc = :left
33
33
  node.xpath('*').each do |node_child|
34
34
  case node_child.name
@@ -16,9 +16,7 @@ module OoxmlParser
16
16
  instance_variables.each do |current_attribute|
17
17
  next if current_attribute == :@parent
18
18
  next if current_attribute == :@is_default
19
- unless instance_variable_get(current_attribute) == other.instance_variable_get(current_attribute)
20
- return false
21
- end
19
+ return false unless instance_variable_get(current_attribute) == other.instance_variable_get(current_attribute)
22
20
  end
23
21
  true
24
22
  end
@@ -10,45 +10,39 @@ module OoxmlParser
10
10
  # @param style_id [String] id to parse
11
11
  # @return [TableStyle] result of parsing
12
12
  def parse(style_id: nil)
13
- unless style_id.nil?
14
- nodes = get_style_node(style_id)
15
- return nil if nodes.nil?
16
- xpath = '*'
17
- attributes = 'style_node_child.name'
18
- end
19
- begin
20
- nodes.xpath(xpath).each do |style_node_child|
21
- case instance_eval(attributes)
22
- when 'wholeTbl'
23
- @whole_table = TableElement.new(parent: self).parse(style_node_child)
24
- when 'band1H'
25
- @banding_1_horizontal = TableElement.new(parent: self).parse(style_node_child)
26
- when 'band2H', 'band2Horz'
27
- @banding_2_horizontal = TableElement.new(parent: self).parse(style_node_child)
28
- when 'band1V'
29
- @banding_1_vertical = TableElement.new(parent: self).parse(style_node_child)
30
- when 'band2V'
31
- @banding_2_vertical = TableElement.new(parent: self).parse(style_node_child)
32
- when 'lastCol'
33
- @last_column = TableElement.new(parent: self).parse(style_node_child)
34
- when 'firstCol'
35
- @first_column = TableElement.new(parent: self).parse(style_node_child)
36
- when 'lastRow'
37
- @last_row = TableElement.new(parent: self).parse(style_node_child)
38
- when 'firstRow'
39
- @first_row = TableElement.new(parent: self).parse(style_node_child)
40
- when 'seCell'
41
- @southeast_cell = TableElement.new(parent: self).parse(style_node_child)
42
- when 'swCell'
43
- @southwest_cell = TableElement.new(parent: self).parse(style_node_child)
44
- when 'neCell'
45
- @northeast_cell = TableElement.new(parent: self).parse(style_node_child)
46
- when 'nwCell'
47
- @northwest_cell = TableElement.new(parent: self).parse(style_node_child)
48
- end
13
+ nodes = get_style_node(style_id)
14
+ return nil unless nodes
15
+ nodes.xpath('*').each do |style_node_child|
16
+ case style_node_child.name
17
+ when 'wholeTbl'
18
+ @whole_table = TableElement.new(parent: self).parse(style_node_child)
19
+ when 'band1H'
20
+ @banding_1_horizontal = TableElement.new(parent: self).parse(style_node_child)
21
+ when 'band2H', 'band2Horz'
22
+ @banding_2_horizontal = TableElement.new(parent: self).parse(style_node_child)
23
+ when 'band1V'
24
+ @banding_1_vertical = TableElement.new(parent: self).parse(style_node_child)
25
+ when 'band2V'
26
+ @banding_2_vertical = TableElement.new(parent: self).parse(style_node_child)
27
+ when 'lastCol'
28
+ @last_column = TableElement.new(parent: self).parse(style_node_child)
29
+ when 'firstCol'
30
+ @first_column = TableElement.new(parent: self).parse(style_node_child)
31
+ when 'lastRow'
32
+ @last_row = TableElement.new(parent: self).parse(style_node_child)
33
+ when 'firstRow'
34
+ @first_row = TableElement.new(parent: self).parse(style_node_child)
35
+ when 'seCell'
36
+ @southeast_cell = TableElement.new(parent: self).parse(style_node_child)
37
+ when 'swCell'
38
+ @southwest_cell = TableElement.new(parent: self).parse(style_node_child)
39
+ when 'neCell'
40
+ @northeast_cell = TableElement.new(parent: self).parse(style_node_child)
41
+ when 'nwCell'
42
+ @northwest_cell = TableElement.new(parent: self).parse(style_node_child)
49
43
  end
50
44
  end
51
- @id = style_id unless style_id.nil?
45
+ @id = style_id
52
46
  self
53
47
  end
54
48
 
@@ -10,6 +10,8 @@ module OoxmlParser
10
10
  attr_accessor :table_cell_properties
11
11
  # @return [TableProperties] properties of table
12
12
  attr_accessor :table_properties
13
+ # @return [TableRowProperties] properties of table row
14
+ attr_reader :table_row_properties
13
15
  # @return [ParagraphProperties] properties of paragraph
14
16
  attr_accessor :paragraph_properties
15
17
  alias cell_properties table_cell_properties
@@ -40,6 +42,8 @@ module OoxmlParser
40
42
  @table_cell_properties = CellProperties.new(parent: self).parse(node_child)
41
43
  when 'tblPr'
42
44
  @table_properties = TableProperties.new(parent: self).parse(node_child)
45
+ when 'trPr'
46
+ @table_row_properties = TableRowProperties.new(parent: self).parse(node_child)
43
47
  when 'pPr'
44
48
  @paragraph_properties = ParagraphProperties.new(parent: self).parse(node_child)
45
49
  end
@@ -15,7 +15,7 @@ module OoxmlParser
15
15
  first_row: :firstRow,
16
16
  last_row: :lastRow }.freeze
17
17
 
18
- TABLE_STYLES_NAMES_HASH.keys.each do |table_style_name|
18
+ TABLE_STYLES_NAMES_HASH.each_key do |table_style_name|
19
19
  define_method(table_style_name) do
20
20
  @table_style_properties_list.each do |table_style|
21
21
  return table_style if table_style.type == TABLE_STYLES_NAMES_HASH[table_style_name]
@@ -29,7 +29,7 @@ module OoxmlParser
29
29
  # with `ooxml_parser` 0.1.2 and earlier
30
30
  # @return [Nothing]
31
31
  def fill_empty_table_styles
32
- TABLE_STYLES_NAMES_HASH.values.each do |current_table_style|
32
+ TABLE_STYLES_NAMES_HASH.each_value do |current_table_style|
33
33
  style_exist = false
34
34
  @table_style_properties_list.each do |existing_style|
35
35
  style_exist = true if existing_style.type == current_table_style
@@ -34,10 +34,10 @@ module OoxmlParser
34
34
  when 'tcPr'
35
35
  @properties = CellProperties.new(parent: self).parse(node_child)
36
36
  when 'p'
37
- @elements << DocumentStructure.default_table_paragraph_style.copy.parse(node_child,
38
- 0,
39
- DocumentStructure.default_table_run_style,
40
- parent: self)
37
+ @elements << DocumentStructure.default_table_paragraph_style.dup.parse(node_child,
38
+ 0,
39
+ DocumentStructure.default_table_run_style,
40
+ parent: self)
41
41
  when 'tbl'
42
42
  @elements << Table.new(parent: self).parse(node_child)
43
43
  end
@@ -18,7 +18,7 @@ module OoxmlParser
18
18
  node.xpath('*').each do |node_child|
19
19
  case node_child.name
20
20
  when 'color'
21
- @color = Color.parse_color_tag(node_child)
21
+ @color = OoxmlColor.new(parent: self).parse(node_child)
22
22
  end
23
23
  end
24
24
  self
@@ -10,7 +10,7 @@ require_relative 'table_properties/table_borders'
10
10
  module OoxmlParser
11
11
  # Class for parsing `w:tblPr` tags
12
12
  class TableProperties < OOXMLDocumentObject
13
- attr_accessor :jc, :table_width, :table_borders, :table_properties, :table_positon, :table_cell_margin, :table_indent, :stretching, :table_style, :row_banding_size,
13
+ attr_accessor :jc, :table_width, :table_borders, :table_positon, :table_cell_margin, :table_indent, :stretching, :table_style, :row_banding_size,
14
14
  :column_banding_size, :table_look, :grid_column, :style
15
15
  # @return [TableStyleColumnBandSize] table style column band size
16
16
  attr_accessor :table_style_column_band_size
@@ -35,21 +35,6 @@ module OoxmlParser
35
35
  @parent = parent
36
36
  end
37
37
 
38
- def copy
39
- table = TableProperties.new
40
- table.jc = @jc
41
- table.table_width = @table_width
42
- table.shade = @shade
43
- table.stretching = @stretching
44
- table.table_borders = @table_borders
45
- table.table_properties = @table_properties
46
- table.table_cell_margin = @table_cell_margin
47
- table.table_indent = @table_indent
48
- table.grid_column = @grid_column
49
- table.style = style
50
- table
51
- end
52
-
53
38
  # Parse TableProperties object
54
39
  # @param node [Nokogiri::XML:Element] node to parse
55
40
  # @return [TableProperties] result of parsing
@@ -1,5 +1,6 @@
1
1
  # noinspection RubyInstanceMethodNamingConvention
2
2
  require_relative 'document_structure/comment'
3
+ require_relative 'document_structure/comments_extended'
3
4
  require_relative 'document_structure/docx_paragraph'
4
5
  require_relative 'document_structure/document_background'
5
6
  require_relative 'document_structure/document_properties'
@@ -25,6 +26,8 @@ module OoxmlParser
25
26
  attr_accessor :theme_colors
26
27
  # @return [DocumentSettings] settings
27
28
  attr_accessor :settings
29
+ # @return [CommentsExtended] extended comments
30
+ attr_accessor :comments_extended
28
31
 
29
32
  def initialize
30
33
  @elements = []
@@ -147,19 +150,22 @@ module OoxmlParser
147
150
  end
148
151
  document.xpath('w:body').each do |body|
149
152
  body.xpath('*').each do |element|
150
- if element.name == 'p'
153
+ case element.name
154
+ when 'p'
151
155
  child = element.child
152
156
  unless child.nil? && doc_structure.elements.last.class == Table
153
- paragraph_style = DocumentStructure.default_paragraph_style.copy.parse(element, number, DocumentStructure.default_run_style, parent: doc_structure)
157
+ paragraph_style = DocumentStructure.default_paragraph_style.dup.parse(element, number, DocumentStructure.default_run_style, parent: doc_structure)
154
158
  number += 1
155
- doc_structure.elements << paragraph_style.copy
159
+ doc_structure.elements << paragraph_style.dup
156
160
  end
157
- elsif element.name == 'tbl'
161
+ when 'tbl'
158
162
  table = Table.new(parent: doc_structure).parse(element,
159
163
  number,
160
164
  TableProperties.new)
161
165
  number += 1
162
166
  doc_structure.elements << table
167
+ when 'sdt'
168
+ doc_structure.elements << StructuredDocumentTag.new(parent: self).parse(element)
163
169
  end
164
170
  end
165
171
  body.xpath('w:sectPr').each do |sect_pr|
@@ -172,7 +178,8 @@ module OoxmlParser
172
178
  end
173
179
  OOXMLDocumentObject.xmls_stack.pop
174
180
  doc_structure.document_properties = DocumentProperties.new(parent: doc_structure).parse
175
- doc_structure.comments = Comment.parse_list
181
+ doc_structure.comments = Comment.parse_list(parent: doc_structure)
182
+ doc_structure.comments_extended = CommentsExtended.new(parent: doc_structure).parse
176
183
  doc_structure.settings = DocumentSettings.new(parent: doc_structure).parse
177
184
  doc_structure
178
185
  end
@@ -194,9 +201,9 @@ module OoxmlParser
194
201
  end
195
202
  end
196
203
  end
197
- DocumentStructure.default_table_paragraph_style = DocumentStructure.default_paragraph_style.copy
204
+ DocumentStructure.default_table_paragraph_style = DocumentStructure.default_paragraph_style.dup
198
205
  DocumentStructure.default_table_paragraph_style.spacing = Spacing.new(0, 0, 1, :auto)
199
- DocumentStructure.default_table_run_style = DocumentStructure.default_run_style.copy
206
+ DocumentStructure.default_table_run_style = DocumentStructure.default_run_style.dup
200
207
  doc.search('//w:style').each do |style|
201
208
  next if style.attribute('default').nil?
202
209
  next unless (style.attribute('default').value == '1' || style.attribute('default').value == 'on' || style.attribute('default').value == 'true') && style.attribute('type').value == 'table'
@@ -8,7 +8,7 @@ module OoxmlParser
8
8
  @paragraphs = paragraphs
9
9
  end
10
10
 
11
- def self.parse_list
11
+ def self.parse_list(parent: nil)
12
12
  comments = []
13
13
  comments_filename = "#{OOXMLDocumentObject.path_to_folder}/#{OOXMLDocumentObject.root_subfolder}/comments.xml"
14
14
  return [] unless File.exist?(comments_filename)
@@ -17,7 +17,7 @@ module OoxmlParser
17
17
  document.xpath('w:comment').each do |comment_tag|
18
18
  comment = Comment.new(comment_tag.attribute('id').value)
19
19
  comment_tag.xpath('w:p').each_with_index do |p, index|
20
- comment.paragraphs << DocxParagraph.new.parse(p, index)
20
+ comment.paragraphs << DocxParagraph.new.parse(p, index, parent: parent)
21
21
  end
22
22
  comments << comment.dup
23
23
  end
@@ -0,0 +1,39 @@
1
+ require_relative 'comments_extended/comment_extended'
2
+ module OoxmlParser
3
+ # Class for parsing `commentsExtended.xml` file
4
+ class CommentsExtended < OOXMLDocumentObject
5
+ def initialize(parent: nil)
6
+ @comments_extended_array = []
7
+ @parent = parent
8
+ end
9
+
10
+ # @return [Array, CommentsExtended] accessor
11
+ def [](key)
12
+ @comments_extended_array[key]
13
+ end
14
+
15
+ # Parse CommentsExtended object
16
+ # @return [CommentsExtended] result of parsing
17
+ def parse
18
+ file_to_parse = OOXMLDocumentObject.path_to_folder + 'word/commentsExtended.xml'
19
+ return nil unless File.exist?(file_to_parse)
20
+ doc = Nokogiri::XML(File.open(file_to_parse))
21
+ doc.xpath('w15:commentsEx/*').each do |node_child|
22
+ case node_child.name
23
+ when 'commentEx'
24
+ @comments_extended_array << CommentExtended.new(parent: self).parse(node_child)
25
+ end
26
+ end
27
+ self
28
+ end
29
+
30
+ # @param id [Integer] id of comment
31
+ # @return [CommentExtended] comment by id
32
+ def by_id(id)
33
+ @comments_extended_array.each do |cur_comment|
34
+ return cur_comment if cur_comment.paragraph_id == id
35
+ end
36
+ nil
37
+ end
38
+ end
39
+ end