ooxml_parser 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) 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/drawing_properties/docx_drawing_distance_from_text.rb +3 -0
  7. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb +1 -0
  8. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb +4 -1
  9. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip.rb +1 -0
  10. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb +4 -0
  11. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_picture.rb +0 -2
  12. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/ooxml_text_box.rb +1 -3
  13. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_color_scheme.rb +1 -0
  14. 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
  15. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_line.rb +1 -0
  16. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties.rb +1 -3
  17. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/old_docx_picture.rb +1 -3
  18. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_properties.rb +1 -3
  19. data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +3 -0
  20. data/lib/ooxml_parser/common_parser/common_data/color.rb +36 -4
  21. data/lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb +5 -0
  22. data/lib/ooxml_parser/common_parser/common_data/colors/hsl_color.rb +11 -0
  23. data/lib/ooxml_parser/common_parser/common_data/colors/scheme_color.rb +1 -0
  24. data/lib/ooxml_parser/common_parser/common_data/colors/theme_colors.rb +4 -0
  25. data/lib/ooxml_parser/common_parser/common_data/content_types.rb +2 -0
  26. data/lib/ooxml_parser/common_parser/common_data/content_types/content_type_default.rb +3 -0
  27. data/lib/ooxml_parser/common_parser/common_data/content_types/content_type_override.rb +3 -0
  28. data/lib/ooxml_parser/common_parser/common_data/coordinates.rb +7 -0
  29. data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +24 -2
  30. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb +3 -0
  31. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +0 -8
  32. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/numbering_properties.rb +2 -0
  33. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_borders.rb +1 -0
  34. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb +16 -13
  35. data/lib/ooxml_parser/common_parser/common_data/table.rb +2 -0
  36. data/lib/ooxml_parser/common_parser/common_data/table/margins/paragraph_margins.rb +3 -0
  37. data/lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb +7 -0
  38. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_position.rb +1 -0
  39. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties/table_style_properties_helper.rb +4 -4
  40. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell_properties.rb +4 -7
  41. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/borders.rb +6 -0
  42. data/lib/ooxml_parser/common_parser/common_data/table/table_grid.rb +3 -0
  43. data/lib/ooxml_parser/common_parser/common_data/underline.rb +4 -0
  44. data/lib/ooxml_parser/docx_parser/docx_data/document_structure.rb +27 -3
  45. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comments/comment.rb +3 -0
  46. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb +2 -0
  47. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph.rb +22 -1
  48. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/bookmark_end.rb +1 -1
  49. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/comment_range_start.rb +1 -0
  50. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/pre_sub_superscript.rb +3 -0
  51. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb +13 -3
  52. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb +4 -1
  53. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb +0 -2
  54. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/frame_properties.rb +3 -0
  55. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb +2 -0
  56. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb +0 -2
  57. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/numbering.rb +5 -0
  58. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb +3 -0
  59. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_size.rb +1 -0
  60. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/styles.rb +2 -0
  61. data/lib/ooxml_parser/docx_parser/docx_parser.rb +3 -0
  62. data/lib/ooxml_parser/name.rb +1 -0
  63. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation.rb +2 -0
  64. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme.rb +3 -0
  65. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme/theme_color.rb +3 -0
  66. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb +3 -0
  67. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node.rb +3 -0
  68. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb +15 -1
  69. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition.rb +3 -0
  70. data/lib/ooxml_parser/pptx_parser/pptx_parser.rb +3 -0
  71. data/lib/ooxml_parser/version.rb +2 -1
  72. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +21 -2
  73. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/chartsheet.rb +3 -0
  74. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache.rb +41 -0
  75. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition.rb +37 -0
  76. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_source.rb +33 -0
  77. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_source/worksheet_source.rb +26 -0
  78. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet.rb +2 -0
  79. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/xf.rb +5 -0
  80. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill.rb +2 -0
  81. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb +3 -0
  82. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +5 -0
  83. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb +4 -0
  84. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb +4 -0
  85. data/lib/ooxml_parser/xlsx_parser/xlsx_parser.rb +3 -0
  86. metadata +64 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af046e45d945d773885e2c8c9c8becef406a7e0c50a1f71161e1252b73295441
4
- data.tar.gz: 16e54721a7a8c6f066693343ad8950c88d136531b9f6a3a53d7d7154c199c699
3
+ metadata.gz: ee9d17ca1564f942a23f3ec27f80e47c92720dcc772f78ce9c05f5b4a083aab4
4
+ data.tar.gz: c7aacc7ac67a9e03aab11180a3d0815c985f10e99494e14ddb65dafc0996d722
5
5
  SHA512:
6
- metadata.gz: 216969571d18f07e04e10c7499628dc59d131a531a7cf1f8abdaf390bba04f04912b5f4f3bc268cd06b45d4853eb9fe3347a1ef136cfa56f2e8f6b88fccde7ab
7
- data.tar.gz: a14b99b7e06bfd36c38fe2e52774e617cc60f94193314b5bad6200fe5d973cc854a8774aa7a43bdcd556bfec6a2f53c0dee59ff978442f49663bd8e3c43a5d2d
6
+ metadata.gz: c9962f8a0a55810dcfe9fccf3f5915059eb1ea89343054fdaefbc835aa8bfdcbd6f492e1684e3944579b90196bf3cde395f34384411f3e8e27fcbb77a89d7e0a
7
+ data.tar.gz: c3422025469da1f6a10c385a0b7bb06d499aaa4e8f6c9c897f40b22a4caf0927288bcd9807e9e859b60f1017e5d31e00caba66dfc29b9d928dd156b5f471abd1
@@ -29,6 +29,7 @@ module OoxmlParser
29
29
  @configuration ||= Configuration.new
30
30
  end
31
31
 
32
+ # Reset settings to default
32
33
  def self.reset
33
34
  @configuration = Configuration.new
34
35
  end
@@ -41,6 +41,9 @@ module OoxmlParser
41
41
  @parent = parent
42
42
  end
43
43
 
44
+ # Parse properties of Chart
45
+ # @param chart_prop_node [Nokogiri::XML:Element] node to parse
46
+ # @return [void]
44
47
  def parse_properties(chart_prop_node)
45
48
  chart_prop_node.xpath('*').each do |chart_props_node_child|
46
49
  case chart_props_node_child.name
@@ -71,6 +74,9 @@ module OoxmlParser
71
74
  extend Gem::Deprecate
72
75
  deprecate :data, 'series points interface', 2020, 1
73
76
 
77
+ # Parse Chart
78
+ # @param parent [OOOXMLDocumentObject] parent of chart
79
+ # @return [Chart] result of parsing
74
80
  def self.parse(parent: nil)
75
81
  chart = Chart.new(parent: parent)
76
82
  chart_xml = chart.parse_xml(OOXMLDocumentObject.current_xml)
@@ -11,7 +11,7 @@ module OoxmlParser
11
11
  attr_reader :order
12
12
  # @return [SeriesText] text of series
13
13
  attr_accessor :text
14
- # @return [Categories] categories of chart
14
+ # @return [SeriesText] categories of chart
15
15
  attr_accessor :categories
16
16
  # @return [DisplayLabelsProperties]
17
17
  attr_accessor :display_labels
@@ -35,7 +35,7 @@ module OoxmlParser
35
35
  when 'tx'
36
36
  @text = SeriesText.new(parent: self).parse(node_child)
37
37
  when 'cat'
38
- @categories = Categories.new(parent: self).parse(node_child)
38
+ @categories = SeriesText.new(parent: self).parse(node_child)
39
39
  when 'dLbls'
40
40
  @display_labels = DisplayLabelsProperties.new(parent: self).parse(node_child)
41
41
  when 'val'
@@ -20,6 +20,4 @@ module OoxmlParser
20
20
  self
21
21
  end
22
22
  end
23
-
24
- Categories = SeriesText
25
23
  end
@@ -5,6 +5,9 @@ module OoxmlParser
5
5
  class DocxDrawingDistanceFromText < OOXMLDocumentObject
6
6
  attr_accessor :top, :bottom, :left, :right
7
7
 
8
+ # Parse DocxDrawingDistanceFromText object
9
+ # @param node [Nokogiri::XML:Element] node to parse
10
+ # @return [DocxDrawingDistanceFromText] result of parsing
8
11
  def parse(node)
9
12
  node.attributes.each do |key, value|
10
13
  case key
@@ -18,6 +18,7 @@ module OoxmlParser
18
18
  end
19
19
  end
20
20
 
21
+ # @return [String] result of convert of object to string
21
22
  def to_s
22
23
  '(' + @x.to_s + '; ' + @y.to_s + ')'
23
24
  end
@@ -28,6 +28,9 @@ module OoxmlParser
28
28
  self
29
29
  end
30
30
 
31
+ # Compare this object to other
32
+ # @param other [Object] any other object
33
+ # @return [True, False] result of comparision
31
34
  def ==(other)
32
35
  (to_base_unit.value - other.to_base_unit.value).abs < 10**(OoxmlParser.configuration.accuracy + 2)
33
36
  end
@@ -40,7 +43,7 @@ module OoxmlParser
40
43
  # @return [String] string representation of size
41
44
  def to_s(unit = :centimeter)
42
45
  converted = to_unit(unit)
43
- "#{converted.value} #{converted.unit}"
46
+ "#{converted.value.to_f} #{converted.unit}"
44
47
  end
45
48
 
46
49
  # Convert all values to one same base unit
@@ -10,6 +10,7 @@ module OoxmlParser
10
10
 
11
11
  alias path path_to_media_file
12
12
 
13
+ # @return [String] result of convert of object to string
13
14
  def to_str
14
15
  path_to_media_file
15
16
  end
@@ -10,6 +10,9 @@ module OoxmlParser
10
10
  # @return [String] content of file
11
11
  attr_accessor :content
12
12
 
13
+ # Parse FileReference object
14
+ # @param node [Nokogiri::XML:Element] node to parse
15
+ # @return [FileReference] result of parsing
13
16
  def parse(node)
14
17
  node.attributes.each do |key, value|
15
18
  case key
@@ -26,6 +29,7 @@ module OoxmlParser
26
29
  return self
27
30
  end
28
31
  return self if @path == 'NULL'
32
+ return self if @path.match?(URI::DEFAULT_PARSER.make_regexp)
29
33
 
30
34
  full_path_to_file = OOXMLDocumentObject.path_to_folder + OOXMLDocumentObject.root_subfolder + @path.gsub('..', '')
31
35
  if File.exist?(full_path_to_file)
@@ -28,6 +28,4 @@ module OoxmlParser
28
28
  self
29
29
  end
30
30
  end
31
-
32
- Picture = DocxPicture
33
31
  end
@@ -3,7 +3,7 @@
3
3
  module OoxmlParser
4
4
  # Class for parsing `txbx` tags
5
5
  class OOXMLTextBox < OOXMLDocumentObject
6
- attr_accessor :properties, :elements
6
+ attr_accessor :elements
7
7
 
8
8
  def initialize(parent: nil)
9
9
  @elements = []
@@ -21,8 +21,6 @@ module OoxmlParser
21
21
  @elements << DocxParagraph.new(parent: self).parse(node_child, index)
22
22
  when 'tbl'
23
23
  @elements << Table.new(parent: self).parse(node_child, index)
24
- when 'bodyPr'
25
- @properties = OOXMLShapeBodyProperties.new(parent: self).parse(node_child)
26
24
  end
27
25
  end
28
26
  self
@@ -35,6 +35,7 @@ module OoxmlParser
35
35
  self
36
36
  end
37
37
 
38
+ # @return [String] result of convert of object to string
38
39
  def to_s
39
40
  "Color: #{@color}, type: #{type}"
40
41
  end
@@ -23,8 +23,6 @@ module OoxmlParser
23
23
  @type = :arc
24
24
  when 'cubicBezTo'
25
25
  @type = :cubic_bezier
26
- when 'quadBezTo'
27
- @type = :quadratic_bezier
28
26
  when 'close'
29
27
  @type = :close
30
28
  end
@@ -16,6 +16,7 @@ module OoxmlParser
16
16
  @parent = parent
17
17
  end
18
18
 
19
+ # @return [Integer] stroke size of object
19
20
  def stroke_size
20
21
  if @color_scheme.nil? || @color_scheme.color == :none
21
22
  0
@@ -10,7 +10,7 @@ require_relative 'custom_geometry/ooxml_custom_geometry'
10
10
  module OoxmlParser
11
11
  # DOCX Shape Properties
12
12
  class DocxShapeProperties < OOXMLDocumentObject
13
- attr_accessor :shape_size, :preset_geometry, :fill_color, :text_box, :line, :custom_geometry
13
+ attr_accessor :shape_size, :preset_geometry, :fill_color, :line, :custom_geometry
14
14
  attr_accessor :blip_fill
15
15
 
16
16
  alias transform shape_size
@@ -33,8 +33,6 @@ module OoxmlParser
33
33
  @shape_size = DocxShapeSize.new(parent: self).parse(node_child)
34
34
  when 'prstGeom'
35
35
  @preset_geometry = PresetGeometry.new(parent: self).parse(node_child)
36
- when 'txbx'
37
- @text_box = TextBox.parse_list(node_child)
38
36
  when 'ln'
39
37
  @line = DocxShapeLine.new(parent: self).parse(node_child)
40
38
  when 'blipFill'
@@ -6,7 +6,7 @@ require_relative 'group/old_docx_group'
6
6
  module OoxmlParser
7
7
  # Fallback DOCX Picture
8
8
  class OldDocxPicture < OOXMLDocumentObject
9
- attr_accessor :data, :type, :style_number
9
+ attr_accessor :data, :type
10
10
 
11
11
  # Parse OldDocxPicture object
12
12
  # @param node [Nokogiri::XML:Element] node to parse
@@ -20,8 +20,6 @@ module OoxmlParser
20
20
  when 'group'
21
21
  @type = :group
22
22
  @data = OldDocxGroup.new(parent: self).parse(node_child)
23
- when 'style'
24
- @style_number = node_child.attribute('val').value.to_i
25
23
  end
26
24
  end
27
25
  self
@@ -3,7 +3,7 @@
3
3
  module OoxmlParser
4
4
  # Fallback DOCX Shape Properties
5
5
  class OldDocxShapeProperties < OOXMLDocumentObject
6
- attr_accessor :fill_color, :opacity, :stroke_color, :stroke_weight
6
+ attr_accessor :fill_color, :stroke_color, :stroke_weight
7
7
 
8
8
  # Parse OldDocxShapeProperties object
9
9
  # @param node [Nokogiri::XML:Element] node to parse
@@ -13,8 +13,6 @@ module OoxmlParser
13
13
  case key
14
14
  when 'fillcolor'
15
15
  @fill_color = Color.new(parent: self).parse_hex_string(value.value.delete('#'))
16
- when 'opacity'
17
- @opacity = value.value.to_f
18
16
  when 'strokecolor'
19
17
  @stroke_color = Color.new(parent: self).parse_hex_string(value.value.delete('#'))
20
18
  when 'strokeweight'
@@ -27,12 +27,15 @@ module OoxmlParser
27
27
  size.zero? && val == :none
28
28
  end
29
29
 
30
+ # @return [String] result of convert of object to string
30
31
  def to_s
31
32
  return '' if nil?
32
33
 
33
34
  "borders color: #{@color}, size: #{size}, space: #{@space}, value: #{@val}"
34
35
  end
35
36
 
37
+ # Method to copy object
38
+ # @return [BordersProperties] copied object
36
39
  def copy
37
40
  BordersProperties.new(@color, size, @val, @space)
38
41
  end
@@ -119,6 +119,7 @@ module OoxmlParser
119
119
  @parent = parent
120
120
  end
121
121
 
122
+ # @return [String] result of convert of object to string
122
123
  def to_s
123
124
  if @red == VALUE_FOR_NONE_COLOR && @green == VALUE_FOR_NONE_COLOR && @blue == VALUE_FOR_NONE_COLOR
124
125
  'none'
@@ -127,33 +128,43 @@ module OoxmlParser
127
128
  end
128
129
  end
129
130
 
131
+ # @return [String] inspect of object for debug means
130
132
  def inspect
131
133
  to_s
132
134
  end
133
135
 
136
+ # @return [String] color in hex value
134
137
  def to_hex
135
138
  (@red.to_s(16).rjust(2, '0') + @green.to_s(16).rjust(2, '0') + @blue.to_s(16).rjust(2, '0')).upcase
136
139
  end
137
140
 
138
141
  alias to_int16 to_hex
139
142
 
143
+ # @return [True, False] is color default
140
144
  def none?
141
145
  (@red == VALUE_FOR_NONE_COLOR) && (@green == VALUE_FOR_NONE_COLOR) && (@blue == VALUE_FOR_NONE_COLOR) ||
142
146
  (style == :nil)
143
147
  end
144
148
 
149
+ # @return [True, False] is color not default
145
150
  def any?
146
151
  !none?
147
152
  end
148
153
 
154
+ # @return [True, False] is color white
149
155
  def white?
150
156
  (@red == 255) && (@green == 255) && (@blue == 255)
151
157
  end
152
158
 
159
+ # Method to copy object
160
+ # @return [Color] copied object
153
161
  def copy
154
162
  Color.new(@red, @green, @blue)
155
163
  end
156
164
 
165
+ # Compare this object to other
166
+ # @param other [Object] any other object
167
+ # @return [True, False] result of comparision
157
168
  def ==(other)
158
169
  if other.is_a?(Color)
159
170
  if (@red == other.red) && (@green == other.green) && (@blue == other.blue)
@@ -190,18 +201,27 @@ module OoxmlParser
190
201
  (self.red - red).abs < delta && (self.green - green).abs < delta && (self.blue - blue).abs < delta ? true : false
191
202
  end
192
203
 
204
+ # Apply tint to color
205
+ # @param tint [Integer] tint to apply
206
+ # @return [void]
193
207
  def calculate_with_tint!(tint)
194
208
  @red += (tint.to_f * (255 - @red)).to_i
195
209
  @green += (tint.to_f * (255 - @green)).to_i
196
210
  @blue += (tint.to_f * (255 - @blue)).to_i
197
211
  end
198
212
 
213
+ # Apply shade to color
214
+ # @param shade [Integer] shade to apply
215
+ # @return [void]
199
216
  def calculate_with_shade!(shade)
200
217
  @red = (@red * shade.to_f).to_i
201
218
  @green = (@green * shade.to_f).to_i
202
219
  @blue = (@blue * shade.to_f).to_i
203
220
  end
204
221
 
222
+ # Parse color scheme data
223
+ # @param scheme_color_node [Nokogiri::XML:Element] node to parse
224
+ # @return [Color] result of parsing
205
225
  def parse_scheme_color(scheme_color_node)
206
226
  color = root_object.theme.color_scheme[scheme_color_node.attribute('val').value.to_sym].color
207
227
  hls = HSLColor.rgb_to_hsl(color)
@@ -229,6 +249,9 @@ module OoxmlParser
229
249
  self
230
250
  end
231
251
 
252
+ # Parse color model data
253
+ # @param color_model_parent_node [Nokogiri::XML:Element] node to parse
254
+ # @return [Color] result of parsing
232
255
  def parse_color_model(color_model_parent_node)
233
256
  color = nil
234
257
  tint = nil
@@ -240,9 +263,6 @@ module OoxmlParser
240
263
  end
241
264
  end
242
265
  case color_model_node.name
243
- when 'scrgbClr'
244
- color = Color.new(color_model_node.attribute('r').value.to_i, color_model_node.attribute('g').value.to_i, color_model_node.attribute('b').value.to_i)
245
- color.alpha_channel = ColorAlphaChannel.parse(color_model_node)
246
266
  when 'srgbClr'
247
267
  color = Color.new.parse_hex_string(color_model_node.attribute('val').value)
248
268
  color.alpha_channel = ColorAlphaChannel.parse(color_model_node)
@@ -261,6 +281,9 @@ module OoxmlParser
261
281
  self
262
282
  end
263
283
 
284
+ # Parse color data
285
+ # @param color_node [Nokogiri::XML:Element] node to parse
286
+ # @return [Color] result of parsing
264
287
  def parse_color(color_node)
265
288
  case color_node.name
266
289
  when 'srgbClr'
@@ -280,6 +303,7 @@ module OoxmlParser
280
303
  end
281
304
 
282
305
  class << self
306
+ # @return [Color] random color
283
307
  def generate_random_color
284
308
  Color.new(rand(256), rand(256), rand(256))
285
309
  end
@@ -293,6 +317,8 @@ module OoxmlParser
293
317
  const_array_name.map { |current_color| Color.parse_string(current_color) }
294
318
  end
295
319
 
320
+ # @param index [Integer] index to get
321
+ # @return [Color] color by it's index
296
322
  def get_rgb_by_color_index(index)
297
323
  color_by_index = COLOR_INDEXED[index]
298
324
  return :unknown if color_by_index.nil?
@@ -300,12 +326,15 @@ module OoxmlParser
300
326
  color_by_index == 'n/a' ? Color.new : Color.new.parse_hex_string(color_by_index)
301
327
  end
302
328
 
329
+ # Parse color from string
330
+ # @param str [String] string to parse
331
+ # @return [Color] result of parsing
303
332
  def parse_string(str)
304
333
  return str if str.is_a?(Color)
305
334
  return Color.new(VALUE_FOR_NONE_COLOR, VALUE_FOR_NONE_COLOR, VALUE_FOR_NONE_COLOR) if str == 'none' || str == '' || str == 'transparent' || str.nil?
306
335
 
307
336
  split = if str.include?('RGB (') || str.include?('rgb(')
308
- str.gsub(/[(RGBrgb\(\) )]/, '').split(',')
337
+ str.gsub(/[(RGBrgb() )]/, '').split(',')
309
338
  elsif str.include?('RGB ') || str.include?('rgb')
310
339
  str.gsub(/RGB |rgb/, '').split(', ')
311
340
  else
@@ -317,6 +346,9 @@ module OoxmlParser
317
346
 
318
347
  alias parse parse_string
319
348
 
349
+ # Convert other object type to Color
350
+ # @param something [Object] object to convert
351
+ # @return [Color] result of conversion
320
352
  def to_color(something)
321
353
  case something
322
354
  when SchemeColor
@@ -18,6 +18,8 @@ module OoxmlParser
18
18
  # @return [Color] rgb color
19
19
  attr_reader :rgb
20
20
 
21
+ # Convert OoxmlColor to other color type
22
+ # @return [Object] result of conversion
21
23
  def to_color
22
24
  return Color.get_rgb_by_color_index(indexed) if indexed
23
25
  return ThemeColors.new(parent: self).parse_color_theme(theme, tint) if theme
@@ -26,6 +28,9 @@ module OoxmlParser
26
28
  value
27
29
  end
28
30
 
31
+ # Compare this object to other
32
+ # @param other [Object] any other object
33
+ # @return [True, False] result of comparision
29
34
  def ==(other)
30
35
  return to_color == other if other.is_a?(Color)
31
36
  return to_color == other if other.is_a?(Symbol)
@@ -19,6 +19,9 @@ module OoxmlParser
19
19
  @l = lightness
20
20
  end
21
21
 
22
+ # Convert rgb color to hsl
23
+ # @param rgb_color [Color] color to convert
24
+ # @return [HSLColor] result of convert
22
25
  def self.rgb_to_hsl(rgb_color)
23
26
  hls_color = HSLColor.new
24
27
  red = rgb_color.red.to_f # / 255.0
@@ -50,6 +53,7 @@ module OoxmlParser
50
53
  end
51
54
 
52
55
  # Chroma - The "colorfulness relative to the brightness of a similarly illuminated white".
56
+ # @return [Color] result
53
57
  def to_rgb
54
58
  chroma = (1 - (2 * @l - 1).abs) * @s
55
59
  x = chroma * (1 - ((@h / 60.0) % 2.0 - 1).abs)
@@ -73,6 +77,10 @@ module OoxmlParser
73
77
  Color.new(((rgb.red + m) * 255.0).round, ((rgb.green + m) * 255.0).round, ((rgb.blue + m) * 255.0).round)
74
78
  end
75
79
 
80
+ # Get lum value of color
81
+ # @param tint [Integer] tint to apply
82
+ # @param lum [Integer] lum without tint
83
+ # @return [Integer] result
76
84
  def calculate_lum_value(tint, lum)
77
85
  if tint.nil?
78
86
  lum
@@ -81,6 +89,9 @@ module OoxmlParser
81
89
  end
82
90
  end
83
91
 
92
+ # Convert to rgb with applied tint
93
+ # @param tint [Integer] tint to apply
94
+ # @return [Color] result of covert
84
95
  def calculate_rgb_with_tint(tint)
85
96
  self.l = calculate_lum_value(tint, @l * 255.0) / 255.0
86
97
  to_rgb