caxlsx 3.4.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/README.md +11 -12
  4. data/Rakefile +7 -5
  5. data/lib/axlsx/content_type/abstract_content_type.rb +9 -4
  6. data/lib/axlsx/content_type/content_type.rb +7 -5
  7. data/lib/axlsx/content_type/default.rb +4 -2
  8. data/lib/axlsx/content_type/override.rb +4 -2
  9. data/lib/axlsx/doc_props/app.rb +26 -24
  10. data/lib/axlsx/doc_props/core.rb +8 -6
  11. data/lib/axlsx/drawing/area_chart.rb +10 -8
  12. data/lib/axlsx/drawing/area_series.rb +12 -10
  13. data/lib/axlsx/drawing/ax_data_source.rb +2 -0
  14. data/lib/axlsx/drawing/axes.rb +6 -4
  15. data/lib/axlsx/drawing/axis.rb +21 -19
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +14 -12
  17. data/lib/axlsx/drawing/bar_chart.rb +13 -11
  18. data/lib/axlsx/drawing/bar_series.rb +8 -6
  19. data/lib/axlsx/drawing/bubble_chart.rb +6 -4
  20. data/lib/axlsx/drawing/bubble_series.rb +8 -6
  21. data/lib/axlsx/drawing/cat_axis.rb +12 -10
  22. data/lib/axlsx/drawing/chart.rb +20 -18
  23. data/lib/axlsx/drawing/d_lbls.rb +7 -5
  24. data/lib/axlsx/drawing/drawing.rb +58 -56
  25. data/lib/axlsx/drawing/graphic_frame.rb +6 -4
  26. data/lib/axlsx/drawing/hyperlink.rb +10 -8
  27. data/lib/axlsx/drawing/line_3D_chart.rb +7 -5
  28. data/lib/axlsx/drawing/line_chart.rb +10 -8
  29. data/lib/axlsx/drawing/line_series.rb +12 -10
  30. data/lib/axlsx/drawing/marker.rb +9 -7
  31. data/lib/axlsx/drawing/num_data.rb +9 -7
  32. data/lib/axlsx/drawing/num_data_source.rb +9 -7
  33. data/lib/axlsx/drawing/num_val.rb +7 -5
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +7 -5
  35. data/lib/axlsx/drawing/pic.rb +16 -14
  36. data/lib/axlsx/drawing/picture_locking.rb +3 -1
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +5 -3
  38. data/lib/axlsx/drawing/pie_series.rb +8 -6
  39. data/lib/axlsx/drawing/scaling.rb +8 -6
  40. data/lib/axlsx/drawing/scatter_chart.rb +7 -5
  41. data/lib/axlsx/drawing/scatter_series.rb +14 -12
  42. data/lib/axlsx/drawing/ser_axis.rb +7 -5
  43. data/lib/axlsx/drawing/series.rb +6 -4
  44. data/lib/axlsx/drawing/series_title.rb +6 -4
  45. data/lib/axlsx/drawing/str_data.rb +7 -5
  46. data/lib/axlsx/drawing/str_val.rb +6 -4
  47. data/lib/axlsx/drawing/title.rb +13 -14
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +4 -2
  49. data/lib/axlsx/drawing/val_axis.rb +4 -2
  50. data/lib/axlsx/drawing/view_3D.rb +9 -7
  51. data/lib/axlsx/drawing/vml_drawing.rb +18 -16
  52. data/lib/axlsx/drawing/vml_shape.rb +24 -22
  53. data/lib/axlsx/package.rb +69 -66
  54. data/lib/axlsx/rels/relationship.rb +10 -5
  55. data/lib/axlsx/rels/relationships.rb +5 -3
  56. data/lib/axlsx/stylesheet/border.rb +6 -4
  57. data/lib/axlsx/stylesheet/border_pr.rb +5 -3
  58. data/lib/axlsx/stylesheet/cell_alignment.rb +12 -10
  59. data/lib/axlsx/stylesheet/cell_protection.rb +5 -3
  60. data/lib/axlsx/stylesheet/cell_style.rb +10 -8
  61. data/lib/axlsx/stylesheet/color.rb +9 -7
  62. data/lib/axlsx/stylesheet/dxf.rb +5 -3
  63. data/lib/axlsx/stylesheet/fill.rb +3 -1
  64. data/lib/axlsx/stylesheet/font.rb +18 -16
  65. data/lib/axlsx/stylesheet/gradient_fill.rb +6 -4
  66. data/lib/axlsx/stylesheet/gradient_stop.rb +6 -4
  67. data/lib/axlsx/stylesheet/num_fmt.rb +8 -10
  68. data/lib/axlsx/stylesheet/pattern_fill.rb +5 -3
  69. data/lib/axlsx/stylesheet/styles.rb +69 -71
  70. data/lib/axlsx/stylesheet/table_style.rb +7 -5
  71. data/lib/axlsx/stylesheet/table_style_element.rb +6 -4
  72. data/lib/axlsx/stylesheet/table_styles.rb +6 -4
  73. data/lib/axlsx/stylesheet/xf.rb +18 -16
  74. data/lib/axlsx/util/accessors.rb +4 -2
  75. data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
  76. data/lib/axlsx/util/constants.rb +117 -104
  77. data/lib/axlsx/util/mime_type_utils.rb +3 -5
  78. data/lib/axlsx/util/options_parser.rb +3 -1
  79. data/lib/axlsx/util/serialized_attributes.rb +42 -17
  80. data/lib/axlsx/util/simple_typed_list.rb +47 -47
  81. data/lib/axlsx/util/storage.rb +11 -10
  82. data/lib/axlsx/util/validators.rb +101 -41
  83. data/lib/axlsx/util/zip_command.rb +10 -10
  84. data/lib/axlsx/version.rb +3 -1
  85. data/lib/axlsx/workbook/defined_name.rb +6 -4
  86. data/lib/axlsx/workbook/defined_names.rb +3 -1
  87. data/lib/axlsx/workbook/shared_strings_table.rb +8 -6
  88. data/lib/axlsx/workbook/workbook.rb +78 -76
  89. data/lib/axlsx/workbook/workbook_view.rb +3 -1
  90. data/lib/axlsx/workbook/workbook_views.rb +3 -1
  91. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +65 -8
  92. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +7 -3
  93. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +11 -7
  94. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  95. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
  96. data/lib/axlsx/workbook/worksheet/border_creator.rb +5 -3
  97. data/lib/axlsx/workbook/worksheet/break.rb +3 -1
  98. data/lib/axlsx/workbook/worksheet/cell.rb +55 -48
  99. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +31 -27
  100. data/lib/axlsx/workbook/worksheet/cfvo.rb +5 -3
  101. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -1
  102. data/lib/axlsx/workbook/worksheet/col.rb +5 -3
  103. data/lib/axlsx/workbook/worksheet/col_breaks.rb +5 -3
  104. data/lib/axlsx/workbook/worksheet/color_scale.rb +12 -10
  105. data/lib/axlsx/workbook/worksheet/cols.rb +3 -1
  106. data/lib/axlsx/workbook/worksheet/comment.rb +8 -6
  107. data/lib/axlsx/workbook/worksheet/comments.rb +6 -4
  108. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +9 -4
  109. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +18 -16
  110. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +3 -1
  111. data/lib/axlsx/workbook/worksheet/data_bar.rb +14 -13
  112. data/lib/axlsx/workbook/worksheet/data_validation.rb +30 -28
  113. data/lib/axlsx/workbook/worksheet/data_validations.rb +3 -1
  114. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +7 -5
  115. data/lib/axlsx/workbook/worksheet/dimension.rb +4 -2
  116. data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -2
  117. data/lib/axlsx/workbook/worksheet/icon_set.rb +23 -6
  118. data/lib/axlsx/workbook/worksheet/merged_cells.rb +5 -5
  119. data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -2
  120. data/lib/axlsx/workbook/worksheet/page_margins.rb +15 -10
  121. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -2
  122. data/lib/axlsx/workbook/worksheet/page_setup.rb +11 -9
  123. data/lib/axlsx/workbook/worksheet/pane.rb +11 -9
  124. data/lib/axlsx/workbook/worksheet/pivot_table.rb +20 -19
  125. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -6
  126. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +2 -0
  127. data/lib/axlsx/workbook/worksheet/print_options.rb +3 -1
  128. data/lib/axlsx/workbook/worksheet/protected_range.rb +3 -1
  129. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +5 -3
  130. data/lib/axlsx/workbook/worksheet/rich_text.rb +3 -1
  131. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +16 -14
  132. data/lib/axlsx/workbook/worksheet/row.rb +6 -7
  133. data/lib/axlsx/workbook/worksheet/row_breaks.rb +6 -4
  134. data/lib/axlsx/workbook/worksheet/selection.rb +9 -7
  135. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -2
  136. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  137. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +6 -2
  138. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +8 -4
  139. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +10 -8
  140. data/lib/axlsx/workbook/worksheet/sheet_view.rb +15 -13
  141. data/lib/axlsx/workbook/worksheet/table.rb +9 -7
  142. data/lib/axlsx/workbook/worksheet/table_style_info.rb +4 -2
  143. data/lib/axlsx/workbook/worksheet/tables.rb +3 -1
  144. data/lib/axlsx/workbook/worksheet/worksheet.rb +38 -37
  145. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -2
  146. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +8 -2
  147. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +6 -4
  148. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +4 -2
  149. data/lib/axlsx.rb +56 -42
  150. data/lib/caxlsx.rb +3 -1
  151. metadata +49 -43
data/lib/axlsx/package.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Package is responsible for managing all the bits and peices that Open Office XML requires to make a valid
3
5
  # xlsx document including validation and serialization.
@@ -31,7 +33,7 @@ module Axlsx
31
33
  # Shortcut to specify that the workbook should use autowidth
32
34
  # @see Workbook#use_autowidth
33
35
  def use_autowidth=(v)
34
- Axlsx::validate_boolean(v);
36
+ Axlsx.validate_boolean(v)
35
37
  workbook.use_autowidth = v
36
38
  end
37
39
 
@@ -44,7 +46,7 @@ module Axlsx
44
46
  # Shortcut to specify that the workbook should use shared strings
45
47
  # @see Workbook#use_shared_strings
46
48
  def use_shared_strings=(v)
47
- Axlsx::validate_boolean(v);
49
+ Axlsx.validate_boolean(v)
48
50
  workbook.use_shared_strings = v
49
51
  end
50
52
 
@@ -99,17 +101,17 @@ module Axlsx
99
101
  # s = p.to_stream()
100
102
  # File.open('example_streamed.xlsx', 'wb') { |f| f.write(s.read) }
101
103
  def serialize(output, options = {}, secondary_options = nil)
102
- if !workbook.styles_applied
104
+ unless workbook.styles_applied
103
105
  workbook.apply_styles
104
106
  end
105
107
 
106
108
  confirm_valid, zip_command = parse_serialize_options(options, secondary_options)
107
- return false unless !confirm_valid || self.validate.empty?
109
+ return false unless !confirm_valid || validate.empty?
108
110
 
109
111
  zip_provider = if zip_command
110
112
  ZipCommand.new(zip_command)
111
113
  else
112
- Zip::OutputStream
114
+ BufferedZipOutputStream
113
115
  end
114
116
  Relationship.initialize_ids_cache
115
117
  zip_provider.open(output) do |zip|
@@ -124,15 +126,16 @@ module Axlsx
124
126
  # @param [Boolean] confirm_valid Validate the package prior to serialization.
125
127
  # @return [StringIO|Boolean] False if confirm_valid and validation errors exist. rewound string IO if not.
126
128
  def to_stream(confirm_valid = false)
127
- if !workbook.styles_applied
129
+ unless workbook.styles_applied
128
130
  workbook.apply_styles
129
131
  end
130
132
 
131
- return false unless !confirm_valid || self.validate.empty?
133
+ return false unless !confirm_valid || validate.empty?
132
134
 
133
135
  Relationship.initialize_ids_cache
134
- zip = write_parts(Zip::OutputStream.new(StringIO.new.binmode, true))
135
- stream = zip.close_buffer
136
+ stream = BufferedZipOutputStream.write_buffer do |zip|
137
+ write_parts(zip)
138
+ end
136
139
  stream.rewind
137
140
  stream
138
141
  ensure
@@ -142,7 +145,7 @@ module Axlsx
142
145
  # Encrypt the package into a CFB using the password provided
143
146
  # This is not ready yet
144
147
  def encrypt(file_name, password)
145
- return false
148
+ false
146
149
  # moc = MsOffCrypto.new(file_name, password)
147
150
  # moc.save
148
151
  end
@@ -156,7 +159,7 @@ module Axlsx
156
159
  #
157
160
  # If by chance you are able to create a package that does not validate it indicates that the internal
158
161
  # validation is not robust enough and needs to be improved. Please report your errors to the gem author.
159
- # @see http://www.ecma-international.org/publications/standards/Ecma-376.htm
162
+ # @see https://www.ecma-international.org/publications-and-standards/standards/ecma-376/
160
163
  # @example
161
164
  # # The following will output any error messages found in serialization.
162
165
  # p = Axlsx::Package.new
@@ -213,57 +216,57 @@ module Axlsx
213
216
  # @private
214
217
  def parts
215
218
  parts = [
216
- { :entry => "xl/#{STYLES_PN}", :doc => workbook.styles, :schema => SML_XSD },
217
- { :entry => CORE_PN, :doc => @core, :schema => CORE_XSD },
218
- { :entry => APP_PN, :doc => @app, :schema => APP_XSD },
219
- { :entry => WORKBOOK_RELS_PN, :doc => workbook.relationships, :schema => RELS_XSD },
220
- { :entry => WORKBOOK_PN, :doc => workbook, :schema => SML_XSD }
219
+ { entry: "xl/#{STYLES_PN}", doc: workbook.styles, schema: SML_XSD },
220
+ { entry: CORE_PN, doc: @core, schema: CORE_XSD },
221
+ { entry: APP_PN, doc: @app, schema: APP_XSD },
222
+ { entry: WORKBOOK_RELS_PN, doc: workbook.relationships, schema: RELS_XSD },
223
+ { entry: WORKBOOK_PN, doc: workbook, schema: SML_XSD }
221
224
  ]
222
225
 
223
226
  workbook.drawings.each do |drawing|
224
- parts << { :entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships, :schema => RELS_XSD }
225
- parts << { :entry => "xl/#{drawing.pn}", :doc => drawing, :schema => DRAWING_XSD }
227
+ parts << { entry: "xl/#{drawing.rels_pn}", doc: drawing.relationships, schema: RELS_XSD }
228
+ parts << { entry: "xl/#{drawing.pn}", doc: drawing, schema: DRAWING_XSD }
226
229
  end
227
230
 
228
231
  workbook.tables.each do |table|
229
- parts << { :entry => "xl/#{table.pn}", :doc => table, :schema => SML_XSD }
232
+ parts << { entry: "xl/#{table.pn}", doc: table, schema: SML_XSD }
230
233
  end
231
234
  workbook.pivot_tables.each do |pivot_table|
232
235
  cache_definition = pivot_table.cache_definition
233
- parts << { :entry => "xl/#{pivot_table.rels_pn}", :doc => pivot_table.relationships, :schema => RELS_XSD }
234
- parts << { :entry => "xl/#{pivot_table.pn}", :doc => pivot_table } # , :schema => SML_XSD}
235
- parts << { :entry => "xl/#{cache_definition.pn}", :doc => cache_definition } # , :schema => SML_XSD}
236
+ parts << { entry: "xl/#{pivot_table.rels_pn}", doc: pivot_table.relationships, schema: RELS_XSD }
237
+ parts << { entry: "xl/#{pivot_table.pn}", doc: pivot_table } # , :schema => SML_XSD}
238
+ parts << { entry: "xl/#{cache_definition.pn}", doc: cache_definition } # , :schema => SML_XSD}
236
239
  end
237
240
 
238
241
  workbook.comments.each do |comment|
239
- if comment.size > 0
240
- parts << { :entry => "xl/#{comment.pn}", :doc => comment, :schema => SML_XSD }
241
- parts << { :entry => "xl/#{comment.vml_drawing.pn}", :doc => comment.vml_drawing, :schema => nil }
242
+ unless comment.empty?
243
+ parts << { entry: "xl/#{comment.pn}", doc: comment, schema: SML_XSD }
244
+ parts << { entry: "xl/#{comment.vml_drawing.pn}", doc: comment.vml_drawing, schema: nil }
242
245
  end
243
246
  end
244
247
 
245
248
  workbook.charts.each do |chart|
246
- parts << { :entry => "xl/#{chart.pn}", :doc => chart, :schema => DRAWING_XSD }
249
+ parts << { entry: "xl/#{chart.pn}", doc: chart, schema: DRAWING_XSD }
247
250
  end
248
251
 
249
252
  workbook.images.each do |image|
250
- parts << { :entry => "xl/#{image.pn}", :path => image.image_src } unless image.remote?
253
+ parts << { entry: "xl/#{image.pn}", path: image.image_src } unless image.remote?
251
254
  end
252
255
 
253
256
  if use_shared_strings
254
- parts << { :entry => "xl/#{SHARED_STRINGS_PN}", :doc => workbook.shared_strings, :schema => SML_XSD }
257
+ parts << { entry: "xl/#{SHARED_STRINGS_PN}", doc: workbook.shared_strings, schema: SML_XSD }
255
258
  end
256
259
 
257
260
  workbook.worksheets.each do |sheet|
258
- parts << { :entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships, :schema => RELS_XSD }
259
- parts << { :entry => "xl/#{sheet.pn}", :doc => sheet, :schema => SML_XSD }
261
+ parts << { entry: "xl/#{sheet.rels_pn}", doc: sheet.relationships, schema: RELS_XSD }
262
+ parts << { entry: "xl/#{sheet.pn}", doc: sheet, schema: SML_XSD }
260
263
  end
261
264
 
262
265
  # Sort parts for correct MIME detection
263
266
  [
264
- { :entry => CONTENT_TYPES_PN, :doc => content_types, :schema => CONTENT_TYPES_XSD },
265
- { :entry => RELS_PN, :doc => relationships, :schema => RELS_XSD },
266
- *(parts.sort_by { |part| part[:entry] }.reverse)
267
+ { entry: CONTENT_TYPES_PN, doc: content_types, schema: CONTENT_TYPES_XSD },
268
+ { entry: RELS_PN, doc: relationships, schema: RELS_XSD },
269
+ *parts.sort_by { |part| part[:entry] }.reverse
267
270
  ]
268
271
  end
269
272
 
@@ -289,56 +292,56 @@ module Axlsx
289
292
  def content_types
290
293
  c_types = base_content_types
291
294
  workbook.drawings.each do |drawing|
292
- c_types << Axlsx::Override.new(:PartName => "/xl/#{drawing.pn}",
293
- :ContentType => DRAWING_CT)
295
+ c_types << Axlsx::Override.new(PartName: "/xl/#{drawing.pn}",
296
+ ContentType: DRAWING_CT)
294
297
  end
295
298
 
296
299
  workbook.charts.each do |chart|
297
- c_types << Axlsx::Override.new(:PartName => "/xl/#{chart.pn}",
298
- :ContentType => CHART_CT)
300
+ c_types << Axlsx::Override.new(PartName: "/xl/#{chart.pn}",
301
+ ContentType: CHART_CT)
299
302
  end
300
303
 
301
304
  workbook.tables.each do |table|
302
- c_types << Axlsx::Override.new(:PartName => "/xl/#{table.pn}",
303
- :ContentType => TABLE_CT)
305
+ c_types << Axlsx::Override.new(PartName: "/xl/#{table.pn}",
306
+ ContentType: TABLE_CT)
304
307
  end
305
308
 
306
309
  workbook.pivot_tables.each do |pivot_table|
307
- c_types << Axlsx::Override.new(:PartName => "/xl/#{pivot_table.pn}",
308
- :ContentType => PIVOT_TABLE_CT)
309
- c_types << Axlsx::Override.new(:PartName => "/xl/#{pivot_table.cache_definition.pn}",
310
- :ContentType => PIVOT_TABLE_CACHE_DEFINITION_CT)
310
+ c_types << Axlsx::Override.new(PartName: "/xl/#{pivot_table.pn}",
311
+ ContentType: PIVOT_TABLE_CT)
312
+ c_types << Axlsx::Override.new(PartName: "/xl/#{pivot_table.cache_definition.pn}",
313
+ ContentType: PIVOT_TABLE_CACHE_DEFINITION_CT)
311
314
  end
312
315
 
313
316
  workbook.comments.each do |comment|
314
- if comment.size > 0
315
- c_types << Axlsx::Override.new(:PartName => "/xl/#{comment.pn}",
316
- :ContentType => COMMENT_CT)
317
+ unless comment.empty?
318
+ c_types << Axlsx::Override.new(PartName: "/xl/#{comment.pn}",
319
+ ContentType: COMMENT_CT)
317
320
  end
318
321
  end
319
322
 
320
- if workbook.comments.size > 0
321
- c_types << Axlsx::Default.new(:Extension => "vml", :ContentType => VML_DRAWING_CT)
323
+ unless workbook.comments.empty?
324
+ c_types << Axlsx::Default.new(Extension: "vml", ContentType: VML_DRAWING_CT)
322
325
  end
323
326
 
324
327
  workbook.worksheets.each do |sheet|
325
- c_types << Axlsx::Override.new(:PartName => "/xl/#{sheet.pn}",
326
- :ContentType => WORKSHEET_CT)
328
+ c_types << Axlsx::Override.new(PartName: "/xl/#{sheet.pn}",
329
+ ContentType: WORKSHEET_CT)
327
330
  end
328
331
  exts = workbook.images.map { |image| image.extname.downcase }
329
332
  exts.uniq.each do |ext|
330
- ct = if ['jpeg', 'jpg'].include?(ext)
333
+ ct = if JPEG_EXS.include?(ext)
331
334
  JPEG_CT
332
- elsif ext == 'gif'
335
+ elsif ext == GIF_EX
333
336
  GIF_CT
334
- elsif ext == 'png'
337
+ elsif ext == PNG_EX
335
338
  PNG_CT
336
339
  end
337
- c_types << Axlsx::Default.new(:ContentType => ct, :Extension => ext)
340
+ c_types << Axlsx::Default.new(ContentType: ct, Extension: ext)
338
341
  end
339
342
  if use_shared_strings
340
- c_types << Axlsx::Override.new(:PartName => "/xl/#{SHARED_STRINGS_PN}",
341
- :ContentType => SHARED_STRINGS_CT)
343
+ c_types << Axlsx::Override.new(PartName: "/xl/#{SHARED_STRINGS_PN}",
344
+ ContentType: SHARED_STRINGS_CT)
342
345
  end
343
346
  c_types
344
347
  end
@@ -347,13 +350,13 @@ module Axlsx
347
350
  # @return [ContentType]
348
351
  # @private
349
352
  def base_content_types
350
- c_types = ContentType.new()
351
- c_types << Default.new(:ContentType => RELS_CT, :Extension => RELS_EX)
352
- c_types << Default.new(:Extension => XML_EX, :ContentType => XML_CT)
353
- c_types << Override.new(:PartName => "/#{APP_PN}", :ContentType => APP_CT)
354
- c_types << Override.new(:PartName => "/#{CORE_PN}", :ContentType => CORE_CT)
355
- c_types << Override.new(:PartName => "/xl/#{STYLES_PN}", :ContentType => STYLES_CT)
356
- c_types << Axlsx::Override.new(:PartName => "/#{WORKBOOK_PN}", :ContentType => WORKBOOK_CT)
353
+ c_types = ContentType.new
354
+ c_types << Default.new(ContentType: RELS_CT, Extension: RELS_EX)
355
+ c_types << Default.new(Extension: XML_EX, ContentType: XML_CT)
356
+ c_types << Override.new(PartName: "/#{APP_PN}", ContentType: APP_CT)
357
+ c_types << Override.new(PartName: "/#{CORE_PN}", ContentType: CORE_CT)
358
+ c_types << Override.new(PartName: "/xl/#{STYLES_PN}", ContentType: STYLES_CT)
359
+ c_types << Axlsx::Override.new(PartName: "/#{WORKBOOK_PN}", ContentType: WORKBOOK_CT)
357
360
  c_types.lock
358
361
  c_types
359
362
  end
@@ -376,19 +379,19 @@ module Axlsx
376
379
  # @private
377
380
  def parse_serialize_options(options, secondary_options)
378
381
  if secondary_options
379
- warn "[DEPRECATION] Axlsx::Package#serialize with 3 arguments is deprecated. " +
382
+ warn "[DEPRECATION] Axlsx::Package#serialize with 3 arguments is deprecated. " \
380
383
  "Use keyword args instead e.g., package.serialize(output, confirm_valid: false, zip_command: 'zip')"
381
384
  end
382
385
  if options.is_a?(Hash)
383
386
  options.merge!(secondary_options || {})
384
387
  invalid_keys = options.keys - [:confirm_valid, :zip_command]
385
388
  if invalid_keys.any?
386
- raise ArgumentError.new("Invalid keyword arguments: #{invalid_keys}")
389
+ raise ArgumentError, "Invalid keyword arguments: #{invalid_keys}"
387
390
  end
388
391
 
389
392
  [options.fetch(:confirm_valid, false), options.fetch(:zip_command, nil)]
390
393
  else
391
- warn "[DEPRECATION] Axlsx::Package#serialize with confirm_valid as a boolean is deprecated. " +
394
+ warn "[DEPRECATION] Axlsx::Package#serialize with confirm_valid as a boolean is deprecated. " \
392
395
  "Use keyword args instead e.g., package.serialize(output, confirm_valid: false)"
393
396
  parse_serialize_options((secondary_options || {}).merge(confirm_valid: options), nil)
394
397
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A relationship defines a reference between package parts.
3
5
  # @note Packages automatically manage relationships.
@@ -41,7 +43,7 @@ module Axlsx
41
43
  end
42
44
 
43
45
  # The id of the relationship (eg. "rId123"). Most instances get their own unique id.
44
- # However, some instances need to share the same id – see {#should_use_same_id_as?}
46
+ # However, some instances need to share the same id – see {#ids_cache_key}
45
47
  # for details.
46
48
  # @return [String]
47
49
  attr_reader :Id
@@ -90,9 +92,9 @@ module Axlsx
90
92
  end
91
93
 
92
94
  # @see Target
93
- def Target=(v) Axlsx::validate_string v; @Target = v end
95
+ def Target=(v) Axlsx.validate_string v; @Target = v end
94
96
  # @see Type
95
- def Type=(v) Axlsx::validate_relationship_type v; @Type = v end
97
+ def Type=(v) Axlsx.validate_relationship_type v; @Type = v end
96
98
 
97
99
  # @see TargetMode
98
100
  def TargetMode=(v) RestrictionValidator.validate 'Relationship.TargetMode', [:External, :Internal], v; @TargetMode = v; end
@@ -100,10 +102,13 @@ module Axlsx
100
102
  # serialize relationship
101
103
  # @param [String] str
102
104
  # @return [String]
103
- def to_xml_string(str = '')
105
+ def to_xml_string(str = +'')
104
106
  h = Axlsx.instance_values_for(self).reject { |k, _| k == "source_obj" }
105
107
  str << '<Relationship '
106
- str << (h.map { |key, value| '' << key.to_s << '="' << Axlsx::coder.encode(value.to_s) << '"' }.join(' '))
108
+ h.each_with_index do |key_value, index|
109
+ str << ' ' unless index.zero?
110
+ str << key_value.first.to_s << '="' << Axlsx.coder.encode(key_value.last.to_s) << '"'
111
+ end
107
112
  str << '/>'
108
113
  end
109
114
 
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
- require 'axlsx/rels/relationship.rb'
4
+ require 'axlsx/rels/relationship'
3
5
 
4
6
  # Relationships are a collection of Relations that define how package parts are related.
5
7
  # @note The package automatically manages releationships.
@@ -19,9 +21,9 @@ module Axlsx
19
21
  # serialize relationships
20
22
  # @param [String] str
21
23
  # @return [String]
22
- def to_xml_string(str = '')
24
+ def to_xml_string(str = +'')
23
25
  str << '<?xml version="1.0" encoding="UTF-8"?>'
24
- str << ('<Relationships xmlns="' << RELS_R << '">')
26
+ str << '<Relationships xmlns="' << RELS_R << '">'
25
27
  each { |rel| rel.to_xml_string(str) }
26
28
  str << '</Relationships>'
27
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # This class details a border used in Office Open XML spreadsheet styles.
3
5
  class Border
@@ -41,20 +43,20 @@ module Axlsx
41
43
  attr_reader :prs
42
44
 
43
45
  # @see diagonalUp
44
- def diagonal_up=(v) Axlsx::validate_boolean v; @diagonal_up = v end
46
+ def diagonal_up=(v) Axlsx.validate_boolean v; @diagonal_up = v end
45
47
  alias :diagonalUp= :diagonal_up=
46
48
 
47
49
  # @see diagonalDown
48
- def diagonal_down=(v) Axlsx::validate_boolean v; @diagonal_down = v end
50
+ def diagonal_down=(v) Axlsx.validate_boolean v; @diagonal_down = v end
49
51
  alias :diagonalDown= :diagonal_down=
50
52
 
51
53
  # @see outline
52
- def outline=(v) Axlsx::validate_boolean v; @outline = v end
54
+ def outline=(v) Axlsx.validate_boolean v; @outline = v end
53
55
 
54
56
  # Serializes the object
55
57
  # @param [String] str
56
58
  # @return [String]
57
- def to_xml_string(str = '')
59
+ def to_xml_string(str = +'')
58
60
  str << '<border '
59
61
  serialized_attributes str
60
62
  str << '>'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A border part.
3
5
  class BorderPr
@@ -60,10 +62,10 @@ module Axlsx
60
62
  # Serializes the object
61
63
  # @param [String] str
62
64
  # @return [String]
63
- def to_xml_string(str = '')
64
- str << ('<' << @name.to_s << ' style="' << @style.to_s << '">')
65
+ def to_xml_string(str = +'')
66
+ str << '<' << @name.to_s << ' style="' << @style.to_s << '">'
65
67
  @color.to_xml_string(str) if @color.is_a?(Color)
66
- str << ('</' << @name.to_s << '>')
68
+ str << '</' << @name.to_s << '>'
67
69
  end
68
70
  end
69
71
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # CellAlignment stores information about the cell alignment of a style Xf Object.
3
5
  # @note Using Styles#add_style is the recommended way to manage cell alignment.
@@ -84,40 +86,40 @@ module Axlsx
84
86
  alias :readingOrder :reading_order
85
87
 
86
88
  # @see horizontal
87
- def horizontal=(v) Axlsx::validate_horizontal_alignment v; @horizontal = v end
89
+ def horizontal=(v) Axlsx.validate_horizontal_alignment v; @horizontal = v end
88
90
  # @see vertical
89
- def vertical=(v) Axlsx::validate_vertical_alignment v; @vertical = v end
91
+ def vertical=(v) Axlsx.validate_vertical_alignment v; @vertical = v end
90
92
  # @see textRotation
91
- def text_rotation=(v) Axlsx::validate_unsigned_int v; @text_rotation = v end
93
+ def text_rotation=(v) Axlsx.validate_unsigned_int v; @text_rotation = v end
92
94
  alias :textRotation= :text_rotation=
93
95
 
94
96
  # @see wrapText
95
- def wrap_text=(v) Axlsx::validate_boolean v; @wrap_text = v end
97
+ def wrap_text=(v) Axlsx.validate_boolean v; @wrap_text = v end
96
98
  alias :wrapText= :wrap_text=
97
99
 
98
100
  # @see indent
99
- def indent=(v) Axlsx::validate_unsigned_int v; @indent = v end
101
+ def indent=(v) Axlsx.validate_unsigned_int v; @indent = v end
100
102
 
101
103
  # @see relativeIndent
102
- def relative_indent=(v) Axlsx::validate_int v; @relative_indent = v end
104
+ def relative_indent=(v) Axlsx.validate_int v; @relative_indent = v end
103
105
  alias :relativeIndent= :relative_indent=
104
106
 
105
107
  # @see justifyLastLine
106
- def justify_last_line=(v) Axlsx::validate_boolean v; @justify_last_line = v end
108
+ def justify_last_line=(v) Axlsx.validate_boolean v; @justify_last_line = v end
107
109
  alias :justifyLastLine= :justify_last_line=
108
110
 
109
111
  # @see shrinkToFit
110
- def shrink_to_fit=(v) Axlsx::validate_boolean v; @shrink_to_fit = v end
112
+ def shrink_to_fit=(v) Axlsx.validate_boolean v; @shrink_to_fit = v end
111
113
  alias :shrinkToFit= :shrink_to_fit=
112
114
 
113
115
  # @see readingOrder
114
- def reading_order=(v) Axlsx::validate_unsigned_int v; @reading_order = v end
116
+ def reading_order=(v) Axlsx.validate_unsigned_int v; @reading_order = v end
115
117
  alias :readingOrder= :reading_order=
116
118
 
117
119
  # Serializes the object
118
120
  # @param [String] str
119
121
  # @return [String]
120
- def to_xml_string(str = '')
122
+ def to_xml_string(str = +'')
121
123
  serialized_tag('alignment', str)
122
124
  end
123
125
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # CellProtection stores information about locking or hiding cells in spreadsheet.
3
5
  # @note Using Styles#add_style is the recommended way to manage cell protection.
@@ -24,14 +26,14 @@ module Axlsx
24
26
  end
25
27
 
26
28
  # @see hidden
27
- def hidden=(v) Axlsx::validate_boolean v; @hidden = v end
29
+ def hidden=(v) Axlsx.validate_boolean v; @hidden = v end
28
30
  # @see locked
29
- def locked=(v) Axlsx::validate_boolean v; @locked = v end
31
+ def locked=(v) Axlsx.validate_boolean v; @locked = v end
30
32
 
31
33
  # Serializes the object
32
34
  # @param [String] str
33
35
  # @return [String]
34
- def to_xml_string(str = '')
36
+ def to_xml_string(str = +'')
35
37
  serialized_tag('protection', str)
36
38
  end
37
39
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # CellStyle defines named styles that reference defined formatting records and can be used in your worksheet.
3
5
  # @note Using Styles#add_style is the recommended way to manage cell styling.
@@ -37,7 +39,7 @@ module Axlsx
37
39
  # @return [Integer]
38
40
  attr_reader :iLevel
39
41
 
40
- # Determines if this named style should show in the list of styles when using excel
42
+ # Determines if this named style should show in the list of styles when using Excel
41
43
  # @return [Boolean]
42
44
  attr_reader :hidden
43
45
 
@@ -46,22 +48,22 @@ module Axlsx
46
48
  attr_reader :customBuiltin
47
49
 
48
50
  # @see name
49
- def name=(v) Axlsx::validate_string v; @name = v end
51
+ def name=(v) Axlsx.validate_string v; @name = v end
50
52
  # @see xfId
51
- def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
53
+ def xfId=(v) Axlsx.validate_unsigned_int v; @xfId = v end
52
54
  # @see builtinId
53
- def builtinId=(v) Axlsx::validate_unsigned_int v; @builtinId = v end
55
+ def builtinId=(v) Axlsx.validate_unsigned_int v; @builtinId = v end
54
56
  # @see iLivel
55
- def iLevel=(v) Axlsx::validate_unsigned_int v; @iLevel = v end
57
+ def iLevel=(v) Axlsx.validate_unsigned_int v; @iLevel = v end
56
58
  # @see hidden
57
- def hidden=(v) Axlsx::validate_boolean v; @hidden = v end
59
+ def hidden=(v) Axlsx.validate_boolean v; @hidden = v end
58
60
  # @see customBuiltin
59
- def customBuiltin=(v) Axlsx::validate_boolean v; @customBuiltin = v end
61
+ def customBuiltin=(v) Axlsx.validate_boolean v; @customBuiltin = v end
60
62
 
61
63
  # Serializes the object
62
64
  # @param [String] str
63
65
  # @return [String]
64
- def to_xml_string(str = '')
66
+ def to_xml_string(str = +'')
65
67
  serialized_tag('cellStyle', str)
66
68
  end
67
69
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The color class represents a color used for borders, fills an fonts
3
5
  class Color
@@ -45,21 +47,21 @@ module Axlsx
45
47
  attr_reader :tint
46
48
 
47
49
  # @see auto
48
- def auto=(v) Axlsx::validate_boolean v; @auto = v end
50
+ def auto=(v) Axlsx.validate_boolean v; @auto = v end
49
51
 
50
52
  # @see color
51
53
  def rgb=(v)
52
- Axlsx::validate_string(v)
54
+ Axlsx.validate_string(v)
53
55
  v = v.upcase
54
- v = v * 3 if v.size == 2
56
+ v *= 3 if v.size == 2
55
57
  v = v.rjust(8, 'FF')
56
- raise ArgumentError, "Invalid color rgb value: #{v}." unless v.match(/[0-9A-F]{8}/)
58
+ raise ArgumentError, "Invalid color rgb value: #{v}." unless /[0-9A-F]{8}/.match?(v)
57
59
 
58
60
  @rgb = v
59
61
  end
60
62
 
61
63
  # @see tint
62
- def tint=(v) Axlsx::validate_float v; @tint = v end
64
+ def tint=(v) Axlsx.validate_float v; @tint = v end
63
65
 
64
66
  # This version does not support themes
65
67
  # def theme=(v) Axlsx::validate_unsigned_integer v; @theme = v end
@@ -70,8 +72,8 @@ module Axlsx
70
72
  # Serializes the object
71
73
  # @param [String] str
72
74
  # @return [String]
73
- def to_xml_string(str = '', tag_name = 'color')
74
- serialized_tag('' + tag_name + '', str)
75
+ def to_xml_string(str = +'', tag_name = 'color')
76
+ serialized_tag(tag_name.to_s, str)
75
77
  end
76
78
  end
77
79
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The Dxf class defines an incremental formatting record for use in Styles. The recommended way to manage styles for your workbook is with Styles#add_style
3
5
  # @see Styles#add_style
@@ -6,7 +8,7 @@ module Axlsx
6
8
 
7
9
  # The order in which the child elements is put in the XML seems to
8
10
  # be important for Excel
9
- CHILD_ELEMENTS = [:font, :numFmt, :fill, :alignment, :border, :protection]
11
+ CHILD_ELEMENTS = [:font, :numFmt, :fill, :alignment, :border, :protection].freeze
10
12
  # does not support extList (ExtensionList)
11
13
 
12
14
  # The cell alignment for this style
@@ -62,12 +64,12 @@ module Axlsx
62
64
  # Serializes the object
63
65
  # @param [String] str
64
66
  # @return [String]
65
- def to_xml_string(str = '')
67
+ def to_xml_string(str = +'')
66
68
  str << '<dxf>'
67
69
  # Dxf elements have no attributes. All of the instance variables
68
70
  # are child elements.
69
71
  CHILD_ELEMENTS.each do |element|
70
- self.send(element).to_xml_string(str) if self.send(element)
72
+ send(element).to_xml_string(str) if send(element)
71
73
  end
72
74
  str << '</dxf>'
73
75
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The Fill is a formatting object that manages the background color, and pattern for cells.
3
5
  # @note The recommended way to manage styles in your workbook is to use Styles#add_style.
@@ -19,7 +21,7 @@ module Axlsx
19
21
  # Serializes the object
20
22
  # @param [String] str
21
23
  # @return [String]
22
- def to_xml_string(str = '')
24
+ def to_xml_string(str = +'')
23
25
  str << '<fill>'
24
26
  @fill_type.to_xml_string(str)
25
27
  str << '</fill>'