ooxml_parser 0.6.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ooxml_parser.rb +1 -0
  3. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +6 -0
  4. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/series.rb +2 -2
  5. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/series/series_text.rb +0 -2
  6. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/docx_drawing.rb +1 -20
  7. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_distance_from_text.rb +3 -0
  8. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_properties.rb +51 -4
  9. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb +1 -0
  10. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb +4 -1
  11. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip.rb +1 -0
  12. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb +4 -0
  13. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_picture.rb +0 -2
  14. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/ooxml_text_box.rb +1 -3
  15. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_color_scheme.rb +1 -0
  16. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/docx_custom_geometry/docx_shape_line_path/docx_shape_line_element.rb +0 -2
  17. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_line.rb +1 -0
  18. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties.rb +12 -4
  19. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_size.rb +10 -3
  20. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/old_docx_picture.rb +1 -3
  21. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_properties.rb +1 -3
  22. data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +3 -0
  23. data/lib/ooxml_parser/common_parser/common_data/color.rb +45 -79
  24. data/lib/ooxml_parser/common_parser/common_data/color/color_helper.rb +4 -3
  25. data/lib/ooxml_parser/common_parser/common_data/color/color_indexes.list +66 -0
  26. data/lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb +5 -0
  27. data/lib/ooxml_parser/common_parser/common_data/colors/color_properties.rb +8 -2
  28. data/lib/ooxml_parser/common_parser/common_data/colors/hsl_color.rb +11 -0
  29. data/lib/ooxml_parser/common_parser/common_data/colors/scheme_color.rb +1 -0
  30. data/lib/ooxml_parser/common_parser/common_data/colors/theme_colors.rb +4 -0
  31. data/lib/ooxml_parser/common_parser/common_data/content_types.rb +2 -0
  32. data/lib/ooxml_parser/common_parser/common_data/content_types/content_type_default.rb +3 -0
  33. data/lib/ooxml_parser/common_parser/common_data/content_types/content_type_override.rb +3 -0
  34. data/lib/ooxml_parser/common_parser/common_data/coordinates.rb +7 -0
  35. data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +14 -3
  36. data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +28 -2
  37. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb +3 -0
  38. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +31 -15
  39. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/outline.rb +4 -2
  40. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/numbering_properties.rb +2 -0
  41. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_borders.rb +1 -0
  42. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb +16 -13
  43. data/lib/ooxml_parser/common_parser/common_data/table.rb +2 -0
  44. data/lib/ooxml_parser/common_parser/common_data/table/margins/paragraph_margins.rb +3 -0
  45. data/lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb +7 -0
  46. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_position.rb +1 -0
  47. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties/table_style_properties_helper.rb +4 -4
  48. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell_properties.rb +4 -5
  49. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/borders.rb +6 -0
  50. data/lib/ooxml_parser/common_parser/common_data/table/table_grid.rb +3 -0
  51. data/lib/ooxml_parser/common_parser/common_data/underline.rb +7 -2
  52. data/lib/ooxml_parser/docx_parser/docx_data/document_structure.rb +41 -9
  53. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comments/comment.rb +3 -0
  54. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb +2 -0
  55. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph.rb +25 -8
  56. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/bookmark_end.rb +1 -1
  57. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/comment_range_start.rb +1 -0
  58. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/pre_sub_superscript.rb +3 -0
  59. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb +13 -3
  60. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb +4 -1
  61. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb +0 -2
  62. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/frame_properties.rb +3 -0
  63. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb +4 -2
  64. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb +8 -4
  65. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/numbering.rb +5 -0
  66. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/columns.rb +3 -1
  67. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb +6 -2
  68. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_size.rb +1 -0
  69. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/styles.rb +2 -0
  70. data/lib/ooxml_parser/docx_parser/docx_parser.rb +3 -0
  71. data/lib/ooxml_parser/name.rb +1 -0
  72. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation.rb +2 -0
  73. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme.rb +3 -0
  74. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme/theme_color.rb +3 -0
  75. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb +5 -2
  76. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node.rb +3 -0
  77. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb +15 -1
  78. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition.rb +3 -0
  79. data/lib/ooxml_parser/pptx_parser/pptx_parser.rb +4 -1
  80. data/lib/ooxml_parser/version.rb +2 -1
  81. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +21 -2
  82. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/chartsheet.rb +3 -0
  83. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache.rb +41 -0
  84. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition.rb +37 -0
  85. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_source.rb +33 -0
  86. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_source/worksheet_source.rb +26 -0
  87. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet.rb +2 -0
  88. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/xf.rb +5 -0
  89. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill.rb +2 -0
  90. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb +3 -0
  91. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +5 -0
  92. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb +4 -0
  93. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb +4 -0
  94. data/lib/ooxml_parser/xlsx_parser/xlsx_parser.rb +3 -0
  95. metadata +65 -4
@@ -10,6 +10,7 @@ module OoxmlParser
10
10
  @parent = parent
11
11
  end
12
12
 
13
+ # @return [AbstractNumbering] AbstractNumbering of current properties
13
14
  def abstruct_numbering
14
15
  root_object.numbering.properties_by_num_id(@numbering_properties)
15
16
  end
@@ -29,6 +30,7 @@ module OoxmlParser
29
30
  self
30
31
  end
31
32
 
33
+ # @return [AbstractNumbering] level list of current numbering
32
34
  def numbering_level_current
33
35
  abstruct_numbering.level_list.each do |current_ilvl|
34
36
  return current_ilvl if current_ilvl.ilvl == @ilvl
@@ -16,6 +16,7 @@ module OoxmlParser
16
16
  # @return [BordersProperties] bar properties
17
17
  attr_accessor :bar
18
18
 
19
+ # @return [Symbol] type of border in visual editor
19
20
  def border_visual_type
20
21
  result = []
21
22
  result << :left if @left.val == :single
@@ -24,28 +24,26 @@ module OoxmlParser
24
24
  @line_rule = line_rule
25
25
  end
26
26
 
27
+ # Compare this object to other
28
+ # @param other [Object] any other object
29
+ # @return [True, False] result of comparision
27
30
  def ==(other)
28
31
  self.line_rule = :at_least if line_rule == 'atLeast'
29
32
  self.line_rule = :multiple if line_rule == :auto
30
33
  other.line_rule = :multiple if other.line_rule == :auto
31
- if self.class == NilClass || other.class == NilClass
32
- return true if self.class == NilClass && other.class == NilClass
34
+ self.line_rule = line_rule.to_sym if line_rule.instance_of?(String)
33
35
 
34
- false
36
+ if @before == other.before &&
37
+ @after == other.after &&
38
+ @line == other.line &&
39
+ @line_rule.to_s == other.line_rule.to_s
40
+ true
35
41
  else
36
- self.line_rule = line_rule.to_sym if line_rule.instance_of?(String)
37
-
38
- if @before == other.before &&
39
- @after == other.after &&
40
- @line == other.line &&
41
- @line_rule.to_s == other.line_rule.to_s
42
- true
43
- else
44
- false
45
- end
42
+ false
46
43
  end
47
44
  end
48
45
 
46
+ # @return [String] result of convert of object to string
49
47
  def to_s
50
48
  result_string = ''
51
49
  variables = instance_variables
@@ -55,10 +53,15 @@ module OoxmlParser
55
53
  result_string
56
54
  end
57
55
 
56
+ # Method to copy object
57
+ # @return [Spacing] copied object
58
58
  def copy
59
59
  Spacing.new(@before, @after, @line, @line_rule)
60
60
  end
61
61
 
62
+ # Round value of spacing
63
+ # @param count_of_digits [Integer] how digits to left
64
+ # @return [Spacing] result of round
62
65
  def round(count_of_digits = 1)
63
66
  before = @before.to_f.round(count_of_digits)
64
67
  after = @after.to_f.round(count_of_digits)
@@ -17,10 +17,12 @@ module OoxmlParser
17
17
 
18
18
  alias table_properties properties
19
19
 
20
+ # @return [String] result of convert of object to string
20
21
  def to_s
21
22
  "Rows: #{@rows.join(',')}"
22
23
  end
23
24
 
25
+ # @return [String] inspect of object for debug means
24
26
  def inspect
25
27
  to_s
26
28
  end
@@ -15,6 +15,9 @@ module OoxmlParser
15
15
  @parent = parent
16
16
  end
17
17
 
18
+ # Parse ParagraphMargins object
19
+ # @param text_body_props_node [Nokogiri::XML:Element] node to parse
20
+ # @return [ParagraphMargins] result of parsing
18
21
  def parse(text_body_props_node)
19
22
  text_body_props_node.attributes.each do |key, value|
20
23
  case key
@@ -15,6 +15,9 @@ module OoxmlParser
15
15
  end
16
16
 
17
17
  # TODO: Separate @is_default attribute and remove this method
18
+ # Compare this object to other
19
+ # @param other [Object] any other object
20
+ # @return [True, False] result of comparision
18
21
  def ==(other)
19
22
  instance_variables.each do |current_attribute|
20
23
  next if current_attribute == :@parent
@@ -24,10 +27,14 @@ module OoxmlParser
24
27
  true
25
28
  end
26
29
 
30
+ # @return [String] result of convert of object to string
27
31
  def to_s
28
32
  'Default: ' + is_default.to_s + ' top: ' + @top.to_s + ', bottom: ' + @bottom.to_s + ', left: ' + @left.to_s + ', right: ' + @right.to_s
29
33
  end
30
34
 
35
+ # Parse TableMargins object
36
+ # @param margin_node [Nokogiri::XML:Element] node to parse
37
+ # @return [TableMargins] result of parsing
31
38
  def parse(margin_node)
32
39
  margin_node.xpath('*').each do |cell_margin_node|
33
40
  case cell_margin_node.name
@@ -6,6 +6,7 @@ module OoxmlParser
6
6
  attr_accessor :left, :right, :top, :bottom, :position_x, :position_y, :horizontal_anchor, :vertical_anchor, :vertical_align_from_anchor,
7
7
  :horizontal_align_from_anchor
8
8
 
9
+ # @return [String] result of convert of object to string
9
10
  def to_s
10
11
  "Table position left: #{left}, "\
11
12
  "right: #{right}, "\
@@ -3,6 +3,7 @@
3
3
  module OoxmlParser
4
4
  # Helper method for working with TableStyleProperties
5
5
  module TableStylePropertiesHelper
6
+ # [Hash] short names for table styles
6
7
  TABLE_STYLES_NAMES_HASH = { first_column: :firstCol,
7
8
  last_column: :lastCol,
8
9
  whole_table: :wholeTbl,
@@ -17,12 +18,11 @@ module OoxmlParser
17
18
  first_row: :firstRow,
18
19
  last_row: :lastRow }.freeze
19
20
 
20
- TABLE_STYLES_NAMES_HASH.each_key do |table_style_name|
21
- define_method(table_style_name) do
21
+ TABLE_STYLES_NAMES_HASH.each do |key, value|
22
+ define_method(key) do
22
23
  @table_style_properties_list.each do |table_style|
23
- return table_style if table_style.type == TABLE_STYLES_NAMES_HASH[table_style_name]
24
+ return table_style if table_style.type == value
24
25
  end
25
- nil
26
26
  end
27
27
  end
28
28
 
@@ -4,7 +4,7 @@ require_relative 'grid_span'
4
4
  module OoxmlParser
5
5
  # Class for parsing 'w:tcPr' element
6
6
  class CellProperties < OOXMLDocumentObject
7
- attr_accessor :fill, :color, :borders, :text_direction, :anchor, :anchor_center, :horizontal_overflow, :table_cell_width, :borders_properties, :vertical_align
7
+ attr_accessor :fill, :color, :borders, :text_direction, :anchor, :table_cell_width, :borders_properties, :vertical_align
8
8
  # @return [GridSpan] data about grid span
9
9
  attr_accessor :grid_span
10
10
  # @return [TableMargins] margins
@@ -25,6 +25,9 @@ module OoxmlParser
25
25
 
26
26
  alias table_cell_borders borders_properties
27
27
 
28
+ # Parse CellProperties object
29
+ # @param node [Nokogiri::XML:Element] node to parse
30
+ # @return [CellProperties] result of parsing
28
31
  def parse(node)
29
32
  @borders_properties = Borders.new
30
33
  @margins = ParagraphMargins.new(parent: self).parse(node)
@@ -78,10 +81,6 @@ module OoxmlParser
78
81
  @text_direction = value.value.to_sym
79
82
  when 'anchor'
80
83
  @anchor = value_to_symbol(value)
81
- when 'anchorCtr'
82
- @anchor_center = value.value
83
- when 'horzOverflow'
84
- @horizontal_overflow = value.value.to_sym
85
84
  end
86
85
  end
87
86
  self
@@ -18,6 +18,8 @@ module OoxmlParser
18
18
  @parent = parent
19
19
  end
20
20
 
21
+ # Method to copy object
22
+ # @return [Borders] copied object
21
23
  def copy
22
24
  new_borders = Borders.new
23
25
  new_borders.left = @left if @left
@@ -32,6 +34,9 @@ module OoxmlParser
32
34
  new_borders
33
35
  end
34
36
 
37
+ # Compare this object to other
38
+ # @param other [Object] any other object
39
+ # @return [True, False] result of comparision
35
40
  def ==(other)
36
41
  @left == other.left && @right == other.right && @top == other.top && @bottom == other.bottom if other.is_a?(Borders)
37
42
  end
@@ -52,6 +57,7 @@ module OoxmlParser
52
57
  yield(top)
53
58
  end
54
59
 
60
+ # @return [String] result of convert of object to string
55
61
  def to_s
56
62
  "Left border: #{left}, Right: #{right}, Top: #{top}, Bottom: #{bottom}"
57
63
  end
@@ -12,6 +12,9 @@ module OoxmlParser
12
12
  @parent = parent
13
13
  end
14
14
 
15
+ # Compare this object to other
16
+ # @param other [Object] any other object
17
+ # @return [True, False] result of comparision
15
18
  def ==(other)
16
19
  @columns.each_with_index do |cur_column, index|
17
20
  return false unless cur_column == other.columns[index]
@@ -11,16 +11,21 @@ module OoxmlParser
11
11
  @parent = parent
12
12
  end
13
13
 
14
+ # Compare this object to other
15
+ # @param other [Object] any other object
16
+ # @return [True, False] result of comparision
14
17
  def ==(other)
15
- if other.is_a? Underline
18
+ case other
19
+ when Underline
16
20
  @style.to_sym == other.style.to_sym && @color == other.color
17
- elsif other.is_a? Symbol
21
+ when Symbol
18
22
  @style.to_sym == other
19
23
  else
20
24
  false
21
25
  end
22
26
  end
23
27
 
28
+ # @return [String] result of convert of object to string
24
29
  def to_s
25
30
  if @color.nil?
26
31
  @style.to_s
@@ -18,12 +18,23 @@ module OoxmlParser
18
18
  class DocumentStructure < CommonDocumentStructure
19
19
  include DocumentStyleHelper
20
20
  include DocumentStructureHelpers
21
- attr_accessor :elements, :page_properties, :notes, :background, :document_properties, :comments
22
-
21
+ # @return [Array<OOXMLDocumentObject>] list of elements
22
+ attr_accessor :elements
23
+ # @return [PageProperties] properties of document
24
+ attr_accessor :page_properties
25
+ # @return [Note] notes of document
26
+ attr_accessor :notes
27
+ # @return [DocumentBackground] background of document
28
+ attr_accessor :background
29
+ # @return [DocumentProperties] properties of document
30
+ attr_accessor :document_properties
31
+ # @return [Comments] comment of document
32
+ attr_accessor :comments
23
33
  # @return [Numbering] store numbering data
24
34
  attr_accessor :numbering
25
35
  # @return [Styles] styles of document
26
36
  attr_accessor :styles
37
+ # @return [PresentationTheme] theme of docx
27
38
  attr_accessor :theme
28
39
  # @return [Relationships] relationships
29
40
  attr_accessor :relationships
@@ -44,6 +55,9 @@ module OoxmlParser
44
55
 
45
56
  alias theme_colors theme
46
57
 
58
+ # Compare this object to other
59
+ # @param other [Object] any other object
60
+ # @return [True, False] result of comparision
47
61
  def ==(other)
48
62
  @elements == other.elements &&
49
63
  @page_properties == other.page_properties &&
@@ -53,6 +67,10 @@ module OoxmlParser
53
67
  @comments == other.comments
54
68
  end
55
69
 
70
+ # Get element by it's type
71
+ # @param location [Symbol] location of object
72
+ # @param type [Symbol] type of object
73
+ # @return [OOXMLDocumentObject]
56
74
  def element_by_description(location: :canvas, type: :docx_paragraph)
57
75
  case location
58
76
  when :canvas
@@ -95,6 +113,9 @@ module OoxmlParser
95
113
  end
96
114
  end
97
115
 
116
+ # Get note by it's description
117
+ # @param type [Symbol] note type
118
+ # @return [Note]
98
119
  def note_by_description(type)
99
120
  notes.each do |note|
100
121
  return note if note.type.to_sym == type
@@ -102,6 +123,11 @@ module OoxmlParser
102
123
  raise 'There isn\'t this type of the note'
103
124
  end
104
125
 
126
+ # Detect numbering type
127
+ # @param location [Symbol] location of object
128
+ # @param type [Symbol] type of object
129
+ # @param paragraph_number [Integer] number of object
130
+ # @return [Array<String,String>] type of numbering
105
131
  def recognize_numbering(location: :canvas, type: :simple, paragraph_number: 0)
106
132
  elements = element_by_description(location: location, type: type)
107
133
  lvl_text = elements[paragraph_number].numbering.abstruct_numbering.level_list[0].text.value
@@ -109,6 +135,11 @@ module OoxmlParser
109
135
  [num_format, lvl_text]
110
136
  end
111
137
 
138
+ # Return outline type
139
+ # @param location [Symbol] location of object
140
+ # @param type [Symbol] type of object
141
+ # @param levels_count [Integer] count of levels to detect
142
+ # @return [Array<String,String>] type of outline
112
143
  def outline(location: :canvas, type: :simple, levels_count: 1)
113
144
  elements = element_by_description(location: location, type: type)
114
145
  set = []
@@ -124,6 +155,8 @@ module OoxmlParser
124
155
  styles.styles
125
156
  end
126
157
 
158
+ # Parse docx file
159
+ # @return [DocumentStructure] parsed structure
127
160
  def self.parse
128
161
  doc_structure = DocumentStructure.new
129
162
  doc_structure.content_types = ContentTypes.new(parent: doc_structure).parse
@@ -181,6 +214,8 @@ module OoxmlParser
181
214
  doc_structure
182
215
  end
183
216
 
217
+ # Parse default style
218
+ # @return [void]
184
219
  def parse_default_style
185
220
  doc = parse_xml(OOXMLDocumentObject.path_to_folder + 'word/styles.xml')
186
221
  doc.search('//w:style').each do |style|
@@ -194,14 +229,14 @@ module OoxmlParser
194
229
  DocumentStructure.default_paragraph_style = DocxParagraph.new.parse_paragraph_style(paragraph_pr_tag, DocumentStructure.default_run_style)
195
230
  end
196
231
  style.xpath('w:rPr').each do |character_pr_tag|
197
- DocumentStructure.default_run_style.parse_properties(character_pr_tag, DocumentStructure.default_run_style)
232
+ DocumentStructure.default_run_style.parse_properties(character_pr_tag)
198
233
  end
199
234
  elsif (style.attribute('default').value == '1' ||
200
235
  style.attribute('default').value == 'on' ||
201
236
  style.attribute('default').value == 'true') &&
202
237
  style.attribute('type').value == 'character'
203
238
  style.xpath('w:rPr').each do |character_pr_tag|
204
- DocumentStructure.default_run_style.parse_properties(character_pr_tag, DocumentStructure.default_run_style)
239
+ DocumentStructure.default_run_style.parse_properties(character_pr_tag)
205
240
  end
206
241
  end
207
242
  end
@@ -216,7 +251,7 @@ module OoxmlParser
216
251
  style.attribute('type').value == 'table'
217
252
 
218
253
  style.xpath('w:rPr').each do |table_character_pr_tag|
219
- DocumentStructure.default_table_run_style.parse_properties(table_character_pr_tag, DocumentStructure.default_run_style)
254
+ DocumentStructure.default_table_run_style.parse_properties(table_character_pr_tag)
220
255
  end
221
256
  end
222
257
  end
@@ -249,10 +284,7 @@ module OoxmlParser
249
284
  end
250
285
 
251
286
  class << self
252
- attr_accessor :default_table_run_style
253
- attr_accessor :default_table_paragraph_style
254
- attr_accessor :default_paragraph_style
255
- attr_accessor :default_run_style
287
+ attr_accessor :default_table_run_style, :default_table_paragraph_style, :default_paragraph_style, :default_run_style
256
288
  end
257
289
  end
258
290
  end
@@ -14,6 +14,9 @@ module OoxmlParser
14
14
  @parent = parent
15
15
  end
16
16
 
17
+ # Parse Comment object
18
+ # @param node [Nokogiri::XML:Element] node to parse
19
+ # @return [Comment] result of parsing
17
20
  def parse(node)
18
21
  node.attributes.each do |key, value|
19
22
  case key
@@ -44,10 +44,12 @@ module OoxmlParser
44
44
  @parent = parent
45
45
  end
46
46
 
47
+ # @return [String] result of convert of object to string
47
48
  def to_s
48
49
  "Table style properties list: #{@table_style_properties_list.join(',')}"
49
50
  end
50
51
 
52
+ # @return [String] inspect of object for debug means
51
53
  def inspect
52
54
  to_s
53
55
  end
@@ -57,6 +57,9 @@ module OoxmlParser
57
57
 
58
58
  alias elements character_style_array
59
59
 
60
+ # Constructor for copy of object
61
+ # @param source [DocxParagraph] original object
62
+ # @return [void]
60
63
  def initialize_copy(source)
61
64
  super
62
65
  @bookmark_start = source.bookmark_start.clone
@@ -65,16 +68,13 @@ module OoxmlParser
65
68
  @spacing = source.spacing.clone
66
69
  end
67
70
 
71
+ # @return [Array<OOXMLDocumentObject>] array of child objects that contains data
68
72
  def nonempty_runs
69
73
  @character_style_array.select do |cur_run|
70
- if cur_run.is_a?(DocxParagraphRun) || cur_run.is_a?(ParagraphRun)
74
+ case cur_run
75
+ when DocxParagraphRun, ParagraphRun
71
76
  !cur_run.empty?
72
- elsif cur_run.is_a?(DocxFormula) ||
73
- cur_run.is_a?(StructuredDocumentTag) ||
74
- cur_run.is_a?(BookmarkStart) ||
75
- cur_run.is_a?(BookmarkEnd) ||
76
- cur_run.is_a?(CommentRangeStart) ||
77
- cur_run.is_a?(CommentRangeEnd)
77
+ when DocxFormula, StructuredDocumentTag, BookmarkStart, BookmarkEnd, CommentRangeStart, CommentRangeEnd
78
78
  true
79
79
  end
80
80
  end
@@ -87,6 +87,9 @@ module OoxmlParser
87
87
  !nonempty_runs.empty? || paragraph_properties.section_properties
88
88
  end
89
89
 
90
+ # Compare this object to other
91
+ # @param other [Object] any other object
92
+ # @return [True, False] result of comparision
90
93
  def ==(other)
91
94
  ignored_attributes = %i[@number @parent]
92
95
  all_instance_variables = instance_variables
@@ -97,6 +100,12 @@ module OoxmlParser
97
100
  true
98
101
  end
99
102
 
103
+ # Parse object
104
+ # @param node [Nokogiri::XML:Node] node with DocxParagraph
105
+ # @param par_number [Integer] number of paragraph
106
+ # @param default_character [DocxParagraphRun] style for paragraph
107
+ # @param parent [OOXMLDocumentObject] parent of run
108
+ # @return [DocxParagraph] result of parse
100
109
  def parse(node, par_number = 0, default_character = DocxParagraphRun.new, parent: nil)
101
110
  @parent ||= parent
102
111
  default_character_style = default_character.dup
@@ -174,6 +183,10 @@ module OoxmlParser
174
183
  self
175
184
  end
176
185
 
186
+ # Parse style
187
+ # @param node [Nokogiri::XML:Node] node with style
188
+ # @param default_char_style [DocxParagraphRun] style for paragraph
189
+ # @return [DocxParagraph] result of parse
177
190
  def parse_paragraph_style(node, default_char_style = DocxParagraphRun.new(parent: self))
178
191
  node.xpath('*').each do |node_child|
179
192
  case node_child.name
@@ -229,6 +242,10 @@ module OoxmlParser
229
242
  self
230
243
  end
231
244
 
245
+ # Parse style xml
246
+ # @param id [String] id of style to parse
247
+ # @param character_style [DocxParagraphRun] style to parse
248
+ # @return [void]
232
249
  def parse_paragraph_style_xml(id, character_style)
233
250
  doc = parse_xml(OOXMLDocumentObject.path_to_folder + 'word/styles.xml')
234
251
  doc.search('//w:style').each do |style|
@@ -239,7 +256,7 @@ module OoxmlParser
239
256
  @style = StyleParametres.new(parent: self).parse(style)
240
257
  end
241
258
  style.xpath('w:rPr').each do |r_pr|
242
- character_style.parse_properties(r_pr, DocumentStructure.default_run_style)
259
+ character_style.parse_properties(r_pr)
243
260
  end
244
261
  break
245
262
  end