xlsxrb 0.1.18 → 0.2.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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +163 -0
  3. data/README.md +34 -11
  4. data/lib/ruby_lsp/xlsxrb/completion_listener.rb +410 -80
  5. data/lib/xlsxrb/chart_builder.rb +251 -386
  6. data/lib/xlsxrb/dsl_helpers.rb +120 -67
  7. data/lib/xlsxrb/elements/cell.rb +37 -157
  8. data/lib/xlsxrb/elements/column.rb +11 -19
  9. data/lib/xlsxrb/elements/coordinate_access.rb +15 -86
  10. data/lib/xlsxrb/elements/image.rb +5 -72
  11. data/lib/xlsxrb/elements/metadata.rb +463 -817
  12. data/lib/xlsxrb/elements/row.rb +27 -145
  13. data/lib/xlsxrb/elements/styles.rb +30 -88
  14. data/lib/xlsxrb/elements/types.rb +6 -99
  15. data/lib/xlsxrb/elements/workbook.rb +19 -126
  16. data/lib/xlsxrb/elements/worksheet.rb +43 -314
  17. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +4 -1
  18. data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +7 -7
  19. data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +32 -17
  20. data/lib/xlsxrb/ooxml/reader.rb +49 -51
  21. data/lib/xlsxrb/ooxml/styles_parser.rb +26 -2
  22. data/lib/xlsxrb/ooxml/utils.rb +2 -2
  23. data/lib/xlsxrb/ooxml/workbook_parser.rb +0 -1
  24. data/lib/xlsxrb/ooxml/workbook_writer.rb +172 -93
  25. data/lib/xlsxrb/ooxml/worksheet_parser.rb +61 -29
  26. data/lib/xlsxrb/ooxml/worksheet_writer.rb +65 -47
  27. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +28 -11
  28. data/lib/xlsxrb/ooxml/writer/features_xml.rb +53 -14
  29. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +1 -1
  30. data/lib/xlsxrb/ooxml/writer.rb +105 -41
  31. data/lib/xlsxrb/ooxml/xml_parser.rb +78 -5
  32. data/lib/xlsxrb/ooxml/zip_reader.rb +65 -15
  33. data/lib/xlsxrb/ooxml/zip_writer.rb +119 -30
  34. data/lib/xlsxrb/stream_row.rb +12 -116
  35. data/lib/xlsxrb/stream_sheet.rb +14 -261
  36. data/lib/xlsxrb/stream_writer.rb +623 -1476
  37. data/lib/xlsxrb/style_builder.rb +376 -593
  38. data/lib/xlsxrb/version.rb +1 -1
  39. data/lib/xlsxrb/workbook_builder.rb +192 -226
  40. data/lib/xlsxrb/worksheet_builder.rb +456 -1324
  41. data/lib/xlsxrb.rb +266 -1083
  42. data/sig/generated/xlsxrb/chart_builder.rbs +202 -205
  43. data/sig/generated/xlsxrb/dsl_helpers.rbs +64 -16
  44. data/sig/generated/xlsxrb/elements/cell.rbs +12 -76
  45. data/sig/generated/xlsxrb/elements/column.rbs +0 -7
  46. data/sig/generated/xlsxrb/elements/coordinate_access.rbs +5 -41
  47. data/sig/generated/xlsxrb/elements/image.rbs +3 -29
  48. data/sig/generated/xlsxrb/elements/metadata.rbs +138 -151
  49. data/sig/generated/xlsxrb/elements/row.rbs +10 -53
  50. data/sig/generated/xlsxrb/elements/styles.rbs +1 -39
  51. data/sig/generated/xlsxrb/elements/workbook.rbs +14 -78
  52. data/sig/generated/xlsxrb/elements/worksheet.rbs +5 -121
  53. data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +0 -4
  54. data/sig/generated/xlsxrb/ooxml/reader.rbs +0 -3
  55. data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +1 -1
  56. data/sig/generated/xlsxrb/ooxml/utils.rbs +3 -3
  57. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +12 -0
  58. data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +16 -0
  59. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +5 -3
  60. data/sig/generated/xlsxrb/ooxml/writer/features_xml.rbs +7 -0
  61. data/sig/generated/xlsxrb/ooxml/writer.rbs +20 -14
  62. data/sig/generated/xlsxrb/ooxml/xml_parser.rbs +70 -0
  63. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +22 -7
  64. data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +26 -1
  65. data/sig/generated/xlsxrb/stream_row.rbs +7 -42
  66. data/sig/generated/xlsxrb/stream_sheet.rbs +1 -158
  67. data/sig/generated/xlsxrb/stream_writer.rbs +457 -976
  68. data/sig/generated/xlsxrb/style_builder.rbs +206 -242
  69. data/sig/generated/xlsxrb/workbook_builder.rbs +84 -132
  70. data/sig/generated/xlsxrb/worksheet_builder.rbs +309 -685
  71. data/sig/generated/xlsxrb.rbs +43 -190
  72. data/sig/rexml.rbs +8 -0
  73. metadata +3 -5
  74. data/lib/xlsxrb/utils.rb +0 -251
  75. data/sig/generated/xlsxrb/utils.rbs +0 -200
@@ -232,8 +232,7 @@ module Xlsxrb
232
232
  sub: "subscript",
233
233
  baseline: "baseline"
234
234
  }.freeze
235
- OMITTED = Object.new.freeze
236
- private_constant :COLORS, :CSS_COLORS, :BORDER_STYLES, :BORDER_INDEX_MAP, :OMITTED
235
+ private_constant :COLORS, :CSS_COLORS, :BORDER_STYLES, :BORDER_INDEX_MAP
237
236
 
238
237
  # Normalizes a color definition (CSS color name, hex code, or RGB integer) to an OpenXML hex color string.
239
238
  #
@@ -313,6 +312,23 @@ module Xlsxrb
313
312
  BORDER_STYLES[sym] || BORDER_STYLES[str.downcase.to_sym]
314
313
  end
315
314
 
315
+ # Normalizes a border style like normalize_border_style, raising ArgumentError for a style
316
+ # that is not one of the ST_BorderStyle values or their snake_case spellings.
317
+ #
318
+ # @param style [Symbol, String, Integer]
319
+ # @return [String]
320
+ # @api private
321
+ #: (Symbol | String | Integer style) -> String
322
+ def self.border_style!(style)
323
+ normalized = normalize_border_style(style)
324
+ return normalized.to_s if normalized
325
+
326
+ suggestion = DidYouMean::SpellChecker.new(dictionary: BORDER_STYLES.keys.map(&:to_s)).correct(style.to_s).first
327
+ message = "unknown border style: #{style.inspect}"
328
+ message += "; did you mean #{BORDER_STYLES[suggestion.to_sym].inspect}?" if suggestion
329
+ raise ArgumentError, message
330
+ end
331
+
316
332
  # Resolves a color symbol, string, or prefix to an aRGB hex string.
317
333
  #
318
334
  # @param color [Symbol, String, Object, nil]
@@ -359,6 +375,60 @@ module Xlsxrb
359
375
  #: Hash[Symbol, untyped]
360
376
  attr_reader :border_props
361
377
 
378
+ # Top-level keys accepted by #apply_options!.
379
+ OPTION_KEYS = %i[
380
+ font bold italic font_size font_name font_color underline strike vert_align superscript subscript
381
+ fill fill_color fill_pattern fill_gradient
382
+ border border_all border_left border_right border_top border_bottom
383
+ number_format
384
+ alignment align_horizontal align_vertical wrap_text text_rotation indent shrink_to_fit
385
+ protection locked hidden
386
+ ].freeze
387
+
388
+ # Keys accepted inside the nested option hashes.
389
+ NESTED_OPTION_KEYS = {
390
+ font: %i[bold italic size name color underline strike vert_align superscript subscript].freeze,
391
+ fill: %i[color pattern fg_color bg_color].freeze,
392
+ fill_pattern: %i[pattern fg_color bg_color].freeze,
393
+ border: %i[all left right top bottom].freeze,
394
+ alignment: %i[horizontal vertical wrap_text text_rotation indent shrink_to_fit].freeze,
395
+ protection: %i[locked hidden].freeze
396
+ }.freeze
397
+
398
+ # Flat keys that the nested form of each group replaces; giving both is ambiguous.
399
+ FLAT_KEYS_BY_GROUP = {
400
+ font: %i[bold italic font_size font_name font_color underline strike vert_align superscript subscript].freeze,
401
+ fill: %i[fill_color fill_pattern].freeze,
402
+ border: %i[border_all border_left border_right border_top border_bottom].freeze,
403
+ alignment: %i[align_horizontal align_vertical wrap_text text_rotation indent shrink_to_fit].freeze,
404
+ protection: %i[locked hidden].freeze
405
+ }.freeze
406
+
407
+ # Copies the option hashes, so a copy can change without affecting the original.
408
+ #: (StyleBuilder source) -> void
409
+ def initialize_copy(source)
410
+ super
411
+ @font_props = @font_props.dup
412
+ @fill_props = @fill_props.dup
413
+ @border_props = @border_props.dup
414
+ @alignment = @alignment.dup
415
+ @protection = @protection.dup
416
+ end
417
+
418
+ # Returns a copy of this style named +name+ that uses +number_format+.
419
+ #
420
+ # @param name [String] Name of the copy.
421
+ # @param number_format [String, Integer] Number format of the copy.
422
+ # @return [StyleBuilder]
423
+ # @api private
424
+ #: (String name, String | Integer number_format) -> StyleBuilder
425
+ def with_number_format(name, number_format)
426
+ copy = dup
427
+ copy.instance_variable_set(:@name, name)
428
+ copy.number_format = number_format
429
+ copy
430
+ end
431
+
362
432
  # Applies option-style definitions so callers can use add_style(name, **opts)
363
433
  # as an alternative to block-based fluent chaining.
364
434
  # Applies option-style definitions so callers can use add_style(name, **opts)
@@ -368,81 +438,37 @@ module Xlsxrb
368
438
  # @api public
369
439
  #: (**untyped) -> self
370
440
  def apply_options!(**opts)
441
+ check_options!(opts)
442
+
371
443
  if opts.key?(:font)
372
444
  font_opts = opts[:font] || {}
373
- bold(font_opts[:bold]) if font_opts.key?(:bold)
374
- italic(font_opts[:italic]) if font_opts.key?(:italic)
375
- if font_opts.key?(:font_size)
376
- warn "[Xlsxrb DEPRECATION] StyleBuilder font option :font_size is deprecated; use :size instead.", uplevel: 1
377
- font_size(font_opts[:font_size])
378
- elsif font_opts.key?(:size)
379
- font_size(font_opts[:size])
380
- elsif font_opts.key?(:sz)
381
- warn "[DEPRECATION] :sz is deprecated; use :font_size or :size instead.", uplevel: 1
382
- font_size(font_opts[:sz])
383
- end
384
- if font_opts.key?(:font_name)
385
- warn "[Xlsxrb DEPRECATION] StyleBuilder font option :font_name is deprecated; use :name instead.", uplevel: 1
386
- font_name(font_opts[:font_name])
387
- elsif font_opts.key?(:name)
388
- font_name(font_opts[:name])
389
- end
390
- if font_opts.key?(:font_color)
391
- warn "[Xlsxrb DEPRECATION] StyleBuilder font option :font_color is deprecated; use :color instead.", uplevel: 1
392
- font_color(font_opts[:font_color])
393
- elsif font_opts.key?(:color)
394
- font_color(font_opts[:color])
395
- end
396
- underline(font_opts[:underline]) if font_opts.key?(:underline)
397
- strike(font_opts[:strike]) if font_opts.key?(:strike)
398
- if font_opts.key?(:vertical_align)
399
- warn "[Xlsxrb DEPRECATION] StyleBuilder font option :vertical_align is deprecated; use :vert_align instead.", uplevel: 1
400
- vert_align(font_opts[:vertical_align])
401
- elsif font_opts.key?(:vert_align)
402
- vert_align(font_opts[:vert_align])
403
- end
404
- superscript(font_opts[:superscript]) if font_opts.key?(:superscript)
405
- subscript(font_opts[:subscript]) if font_opts.key?(:subscript)
445
+ self.bold = font_opts[:bold] if font_opts.key?(:bold)
446
+ self.italic = font_opts[:italic] if font_opts.key?(:italic)
447
+ self.font_size = font_opts[:size] if font_opts.key?(:size)
448
+ self.font_name = font_opts[:name] if font_opts.key?(:name)
449
+ self.font_color = font_opts[:color] if font_opts.key?(:color)
450
+ self.underline = font_opts[:underline] if font_opts.key?(:underline)
451
+ self.strike = font_opts[:strike] if font_opts.key?(:strike)
452
+ self.vert_align = font_opts[:vert_align] if font_opts.key?(:vert_align)
453
+ self.superscript = font_opts[:superscript] if font_opts.key?(:superscript)
454
+ self.subscript = font_opts[:subscript] if font_opts.key?(:subscript)
406
455
  else
407
- bold(opts[:bold]) if opts.key?(:bold)
408
- italic(opts[:italic]) if opts.key?(:italic)
409
- if opts.key?(:size)
410
- warn "[Xlsxrb DEPRECATION] StyleBuilder option :size is deprecated; use :font_size instead.", uplevel: 1
411
- font_size(opts[:size])
412
- elsif opts.key?(:font_size)
413
- font_size(opts[:font_size])
414
- elsif opts.key?(:sz)
415
- warn "[DEPRECATION] :sz is deprecated; use :font_size or :size instead.", uplevel: 1
416
- font_size(opts[:sz])
417
- end
418
- if opts.key?(:name)
419
- warn "[Xlsxrb DEPRECATION] StyleBuilder option :name is deprecated; use :font_name instead.", uplevel: 1
420
- font_name(opts[:name])
421
- elsif opts.key?(:font_name)
422
- font_name(opts[:font_name])
423
- end
424
- if opts.key?(:color)
425
- warn "[Xlsxrb DEPRECATION] StyleBuilder option :color is deprecated; use :font_color instead.", uplevel: 1
426
- font_color(opts[:color])
427
- elsif opts.key?(:font_color)
428
- font_color(opts[:font_color])
429
- end
430
- underline(opts[:underline]) if opts.key?(:underline)
431
- strike(opts[:strike]) if opts.key?(:strike)
432
- if opts.key?(:vertical_align)
433
- warn "[Xlsxrb DEPRECATION] StyleBuilder option :vertical_align is deprecated; use :vert_align instead.", uplevel: 1
434
- vert_align(opts[:vertical_align])
435
- elsif opts.key?(:vert_align)
436
- vert_align(opts[:vert_align])
437
- end
438
- superscript(opts[:superscript]) if opts.key?(:superscript)
439
- subscript(opts[:subscript]) if opts.key?(:subscript)
456
+ self.bold = opts[:bold] if opts.key?(:bold)
457
+ self.italic = opts[:italic] if opts.key?(:italic)
458
+ self.font_size = opts[:font_size] if opts.key?(:font_size)
459
+ self.font_name = opts[:font_name] if opts.key?(:font_name)
460
+ self.font_color = opts[:font_color] if opts.key?(:font_color)
461
+ self.underline = opts[:underline] if opts.key?(:underline)
462
+ self.strike = opts[:strike] if opts.key?(:strike)
463
+ self.vert_align = opts[:vert_align] if opts.key?(:vert_align)
464
+ self.superscript = opts[:superscript] if opts.key?(:superscript)
465
+ self.subscript = opts[:subscript] if opts.key?(:subscript)
440
466
  end
441
467
 
442
468
  if opts.key?(:fill)
443
469
  fill_opts = opts[:fill] || {}
444
470
  if fill_opts.key?(:color)
445
- fill_color(fill_opts[:color])
471
+ self.fill_color = fill_opts[:color]
446
472
  else
447
473
  fill_pattern(
448
474
  fill_opts[:pattern] || "solid",
@@ -451,7 +477,7 @@ module Xlsxrb
451
477
  )
452
478
  end
453
479
  else
454
- fill_color(opts[:fill_color]) if opts.key?(:fill_color)
480
+ self.fill_color = opts[:fill_color] if opts.key?(:fill_color)
455
481
  if opts.key?(:fill_pattern)
456
482
  pattern = opts[:fill_pattern] || {}
457
483
  fill_pattern(
@@ -478,37 +504,32 @@ module Xlsxrb
478
504
  border_bottom(**opts[:border_bottom]) if opts.key?(:border_bottom) && opts[:border_bottom]
479
505
  end
480
506
 
481
- if opts.key?(:number_format_id)
482
- warn "[Xlsxrb DEPRECATION] StyleBuilder option :number_format_id is deprecated; use :number_format instead.", uplevel: 1
483
- number_format(opts[:number_format_id])
484
- elsif opts.key?(:number_format)
485
- number_format(opts[:number_format])
486
- end
507
+ self.number_format = opts[:number_format] if opts.key?(:number_format)
487
508
 
488
509
  if opts.key?(:alignment)
489
510
  align_opts = opts[:alignment] || {}
490
- align_horizontal(align_opts[:horizontal]) if align_opts.key?(:horizontal)
491
- align_vertical(align_opts[:vertical]) if align_opts.key?(:vertical)
492
- wrap_text(align_opts[:wrap_text]) if align_opts.key?(:wrap_text)
493
- text_rotation(align_opts[:text_rotation]) if align_opts.key?(:text_rotation)
494
- indent(align_opts[:indent]) if align_opts.key?(:indent)
495
- shrink_to_fit(align_opts[:shrink_to_fit]) if align_opts.key?(:shrink_to_fit)
511
+ self.align_horizontal = align_opts[:horizontal] if align_opts.key?(:horizontal)
512
+ self.align_vertical = align_opts[:vertical] if align_opts.key?(:vertical)
513
+ self.wrap_text = align_opts[:wrap_text] if align_opts.key?(:wrap_text)
514
+ self.text_rotation = align_opts[:text_rotation] if align_opts.key?(:text_rotation)
515
+ self.indent = align_opts[:indent] if align_opts.key?(:indent)
516
+ self.shrink_to_fit = align_opts[:shrink_to_fit] if align_opts.key?(:shrink_to_fit)
496
517
  else
497
- align_horizontal(opts[:align_horizontal]) if opts.key?(:align_horizontal)
498
- align_vertical(opts[:align_vertical]) if opts.key?(:align_vertical)
499
- wrap_text(opts[:wrap_text]) if opts.key?(:wrap_text)
500
- text_rotation(opts[:text_rotation]) if opts.key?(:text_rotation)
501
- indent(opts[:indent]) if opts.key?(:indent)
502
- shrink_to_fit(opts[:shrink_to_fit]) if opts.key?(:shrink_to_fit)
518
+ self.align_horizontal = opts[:align_horizontal] if opts.key?(:align_horizontal)
519
+ self.align_vertical = opts[:align_vertical] if opts.key?(:align_vertical)
520
+ self.wrap_text = opts[:wrap_text] if opts.key?(:wrap_text)
521
+ self.text_rotation = opts[:text_rotation] if opts.key?(:text_rotation)
522
+ self.indent = opts[:indent] if opts.key?(:indent)
523
+ self.shrink_to_fit = opts[:shrink_to_fit] if opts.key?(:shrink_to_fit)
503
524
  end
504
525
 
505
526
  if opts.key?(:protection)
506
527
  prot_opts = opts[:protection] || {}
507
- locked(prot_opts[:locked]) if prot_opts.key?(:locked)
508
- hidden(prot_opts[:hidden]) if prot_opts.key?(:hidden)
528
+ self.locked = prot_opts[:locked] if prot_opts.key?(:locked)
529
+ self.hidden = prot_opts[:hidden] if prot_opts.key?(:hidden)
509
530
  else
510
- locked(opts[:locked]) if opts.key?(:locked)
511
- hidden(opts[:hidden]) if opts.key?(:hidden)
531
+ self.locked = opts[:locked] if opts.key?(:locked)
532
+ self.hidden = opts[:hidden] if opts.key?(:hidden)
512
533
  end
513
534
 
514
535
  self
@@ -516,70 +537,36 @@ module Xlsxrb
516
537
 
517
538
  # --- Font Properties ---
518
539
 
519
- # Configures multiple font properties at once.
540
+ # Configures multiple font properties at once or returns font properties.
520
541
  # @param opts [Hash] The font properties.
521
- # @return [self]
542
+ # @return [Hash, void]
522
543
  # @api public
523
- #: (**untyped) -> (self | Hash[Symbol, untyped])
544
+ #: () -> Hash[Symbol, untyped]
545
+ #: (**untyped) -> void
524
546
  def font(**opts)
525
547
  return @font_props if opts.empty?
526
548
 
527
- bold(opts[:bold]) if opts.key?(:bold)
528
- italic(opts[:italic]) if opts.key?(:italic)
529
- if opts.key?(:font_size)
530
- warn "[Xlsxrb DEPRECATION] StyleBuilder font option :font_size is deprecated; use :size instead.", uplevel: 1
531
- font_size(opts[:font_size])
532
- elsif opts.key?(:size)
533
- font_size(opts[:size])
534
- elsif opts.key?(:sz)
535
- warn "[DEPRECATION] :sz is deprecated; use :font_size or :size instead.", uplevel: 1
536
- font_size(opts[:sz])
537
- end
538
- if opts.key?(:font_name)
539
- warn "[Xlsxrb DEPRECATION] StyleBuilder font option :font_name is deprecated; use :name instead.", uplevel: 1
540
- font_name(opts[:font_name])
541
- elsif opts.key?(:name)
542
- font_name(opts[:name])
543
- end
544
- if opts.key?(:font_color)
545
- warn "[Xlsxrb DEPRECATION] StyleBuilder font option :font_color is deprecated; use :color instead.", uplevel: 1
546
- font_color(opts[:font_color])
547
- elsif opts.key?(:color)
548
- font_color(opts[:color])
549
- end
550
- underline(opts[:underline]) if opts.key?(:underline)
551
- strike(opts[:strike]) if opts.key?(:strike)
552
- if opts.key?(:vertical_align)
553
- warn "[Xlsxrb DEPRECATION] StyleBuilder font option :vertical_align is deprecated; use :vert_align instead.", uplevel: 1
554
- vert_align(opts[:vertical_align])
555
- elsif opts.key?(:vert_align)
556
- vert_align(opts[:vert_align])
557
- end
558
- superscript(opts[:superscript]) if opts.key?(:superscript)
559
- subscript(opts[:subscript]) if opts.key?(:subscript)
560
- self
549
+ self.bold = opts[:bold] if opts.key?(:bold)
550
+ self.italic = opts[:italic] if opts.key?(:italic)
551
+ self.font_size = opts[:size] if opts.key?(:size)
552
+ self.font_name = opts[:name] if opts.key?(:name)
553
+ self.font_color = opts[:color] if opts.key?(:color)
554
+ self.underline = opts[:underline] if opts.key?(:underline)
555
+ self.strike = opts[:strike] if opts.key?(:strike)
556
+ self.vert_align = opts[:vert_align] if opts.key?(:vert_align)
557
+ self.superscript = opts[:superscript] if opts.key?(:superscript)
558
+ self.subscript = opts[:subscript] if opts.key?(:subscript)
559
+ nil
561
560
  end
562
561
 
562
+ # Sets font options.
563
+ # @param opts [Hash]
564
+ # @return [Hash]
565
+ # @api public
566
+ #: (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
563
567
  def font=(opts)
564
568
  font(**opts)
565
- end
566
-
567
- # Sets the font to bold.
568
- # @param value [Boolean] Whether to apply bold.
569
- # @return [self]
570
- # @api public
571
- #: (?untyped) -> (self | bool)
572
- def bold(value = OMITTED)
573
- if value.equal?(OMITTED)
574
- return bold? unless @font_props[:bold].nil?
575
-
576
- Xlsxrb::Deprecation.warn("Calling StyleBuilder#bold with zero arguments as a mutator is deprecated; pass true explicitly (e.g. bold(true))", uplevel: 1)
577
- @font_props[:bold] = true
578
- return self
579
- end
580
-
581
- @font_props[:bold] = value ? true : false
582
- self
569
+ opts
583
570
  end
584
571
 
585
572
  # Sets the font to bold.
@@ -588,7 +575,7 @@ module Xlsxrb
588
575
  # @api public
589
576
  #: (bool value) -> bool
590
577
  def bold=(value)
591
- @font_props[:bold] = value
578
+ @font_props[:bold] = value ? true : false
592
579
  end
593
580
 
594
581
  # Returns whether bold is enabled.
@@ -599,31 +586,13 @@ module Xlsxrb
599
586
  @font_props[:bold] ? true : false
600
587
  end
601
588
 
602
- # Sets the font to italic.
603
- # @param value [Boolean] Whether to apply italic.
604
- # @return [self]
605
- # @api public
606
- #: (?untyped) -> (self | bool)
607
- def italic(value = OMITTED)
608
- if value.equal?(OMITTED)
609
- return italic? unless @font_props[:italic].nil?
610
-
611
- Xlsxrb::Deprecation.warn("Calling StyleBuilder#italic with zero arguments as a mutator is deprecated; pass true explicitly (e.g. italic(true))", uplevel: 1)
612
- @font_props[:italic] = true
613
- return self
614
- end
615
-
616
- @font_props[:italic] = value ? true : false
617
- self
618
- end
619
-
620
589
  # Sets the font to italic.
621
590
  # @param value [Boolean]
622
591
  # @return [Boolean]
623
592
  # @api public
624
593
  #: (bool value) -> bool
625
594
  def italic=(value)
626
- @font_props[:italic] = value
595
+ @font_props[:italic] = value ? true : false
627
596
  end
628
597
 
629
598
  # Returns whether italic is enabled.
@@ -634,20 +603,12 @@ module Xlsxrb
634
603
  @font_props[:italic] ? true : false
635
604
  end
636
605
 
637
- # Sets or gets the font size in points.
638
- # @param size_value [Integer, Float, nil] The size in points (supports fractional sizes such as 10.5).
639
- # @return [Integer, Float, self, nil]
606
+ # Gets the font size in points.
607
+ # @return [Integer, Float, nil]
640
608
  # @api public
641
- #: (?Numeric? size_value) -> (Numeric | self | nil)
642
- def font_size(size_value = nil)
643
- if size_value.nil?
644
- @font_props[:size] || @font_props[:sz]
645
- else
646
- val = size_value.is_a?(Float) && (size_value % 1).zero? ? size_value.to_i : size_value
647
- @font_props[:size] = val
648
- @font_props[:sz] = val
649
- self
650
- end
609
+ #: () -> (Integer | Float | nil)
610
+ def font_size
611
+ @font_props[:size]
651
612
  end
652
613
 
653
614
  # Sets the font size in points.
@@ -658,49 +619,15 @@ module Xlsxrb
658
619
  def font_size=(size_value)
659
620
  val = size_value.is_a?(Float) && (size_value % 1).zero? ? size_value.to_i : size_value
660
621
  @font_props[:size] = val
661
- @font_props[:sz] = val
662
622
  size_value
663
623
  end
664
624
 
665
- # @deprecated Use {#font_size} instead. Will be removed in 0.2.0.
666
- #: (?Numeric? size_value) -> (Numeric | self | nil)
667
- def size(size_value = nil)
668
- warn "[DEPRECATION] #size is deprecated; use #font_size instead.", uplevel: 1
669
- font_size(size_value)
670
- end
671
-
672
- # @deprecated Use {#font_size=} instead. Will be removed in 0.2.0.
673
- #: (Numeric size_value) -> Numeric
674
- def size=(size_value)
675
- warn "[DEPRECATION] #size= is deprecated; use #font_size= instead.", uplevel: 1
676
- self.font_size = size_value
677
- end
678
-
679
- # @deprecated Use {#font_size} instead. Will be removed in 0.2.0.
680
- #: (?Numeric? size_value) -> (Numeric | self | nil)
681
- def sz(size_value = nil)
682
- warn "[DEPRECATION] #sz is deprecated; use #font_size instead.", uplevel: 1
683
- font_size(size_value)
684
- end
685
-
686
- # @deprecated Use {#font_size=} instead. Will be removed in 0.2.0.
687
- #: (Numeric size_value) -> Numeric
688
- def sz=(size_value)
689
- warn "[DEPRECATION] #sz= is deprecated; use #font_size= instead.", uplevel: 1
690
- self.font_size = size_value
691
- end
692
-
693
- # Sets the font name.
694
- # Gets or sets the font name.
695
- # @param name [String, Object] The font name.
696
- # @return [String, self, nil]
625
+ # Gets the font name.
626
+ # @return [String, nil]
697
627
  # @api public
698
- #: (?untyped name) -> (String | self | nil)
699
- def font_name(name = OMITTED)
700
- return @font_props[:name] if name.equal?(OMITTED)
701
-
702
- @font_props[:name] = name
703
- self
628
+ #: () -> String?
629
+ def font_name
630
+ @font_props[:name]
704
631
  end
705
632
 
706
633
  # Sets the font name.
@@ -712,16 +639,12 @@ module Xlsxrb
712
639
  @font_props[:name] = name
713
640
  end
714
641
 
715
- # Gets or sets the font color.
716
- # @param color [String, Symbol, Object] The color.
717
- # @return [String, Symbol, self, nil]
642
+ # Gets the font color.
643
+ # @return [String, nil]
718
644
  # @api public
719
- #: (?untyped color) -> (String | Symbol | self | nil)
720
- def font_color(color = OMITTED)
721
- return @font_props[:color] if color.equal?(OMITTED)
722
-
723
- @font_props[:color] = resolve_color(color)
724
- self
645
+ #: () -> String?
646
+ def font_color
647
+ @font_props[:color]
725
648
  end
726
649
 
727
650
  # Sets the font color.
@@ -734,20 +657,20 @@ module Xlsxrb
734
657
  color
735
658
  end
736
659
 
737
- # Sets the font underline style.
738
- # @param val [String, Symbol, Boolean] The underline style (e.g., 'single', :double, :single_accounting, :double_accounting).
739
- # @return [self]
660
+ # Gets the font underline style.
661
+ # @return [String, Symbol, Boolean, nil]
740
662
  # @api public
741
- #: (?untyped) -> (self | String | Symbol | bool | nil)
742
- def underline(val = OMITTED)
743
- if val.equal?(OMITTED)
744
- return @font_props[:underline] unless @font_props[:underline].nil?
745
-
746
- Xlsxrb::Deprecation.warn("Calling StyleBuilder#underline with zero arguments as a mutator is deprecated; pass true explicitly (e.g. underline(true))", uplevel: 1)
747
- @font_props[:underline] = "single"
748
- return self
749
- end
663
+ #: () -> (String | Symbol | bool | nil)
664
+ def underline
665
+ @font_props[:underline]
666
+ end
750
667
 
668
+ # Sets the font underline style.
669
+ # @param val [String, Symbol, Boolean]
670
+ # @return [String, Symbol, Boolean]
671
+ # @api public
672
+ #: (String | Symbol | bool val) -> (String | Symbol | bool)
673
+ def underline=(val)
751
674
  mapped = if [true, "single"].include?(val)
752
675
  "single"
753
676
  elsif val == false
@@ -756,16 +679,6 @@ module Xlsxrb
756
679
  UNDERLINE_MAP[val.to_sym] || val.to_s
757
680
  end
758
681
  @font_props[:underline] = mapped
759
- self
760
- end
761
-
762
- # Sets the font underline style.
763
- # @param val [String, Symbol, Boolean]
764
- # @return [String, Symbol, Boolean]
765
- # @api public
766
- #: (String | Symbol | bool val) -> (String | Symbol | bool)
767
- def underline=(val)
768
- underline(val)
769
682
  val
770
683
  end
771
684
 
@@ -777,31 +690,13 @@ module Xlsxrb
777
690
  !@font_props[:underline].nil? && @font_props[:underline] != false
778
691
  end
779
692
 
780
- # Sets the font strikethrough.
781
- # @param value [Boolean] Whether to apply strike.
782
- # @return [self]
783
- # @api public
784
- #: (?untyped) -> (self | bool)
785
- def strike(value = OMITTED)
786
- if value.equal?(OMITTED)
787
- return strike? unless @font_props[:strike].nil?
788
-
789
- Xlsxrb::Deprecation.warn("Calling StyleBuilder#strike with zero arguments as a mutator is deprecated; pass true explicitly (e.g. strike(true))", uplevel: 1)
790
- @font_props[:strike] = true
791
- return self
792
- end
793
-
794
- @font_props[:strike] = value ? true : false
795
- self
796
- end
797
-
798
693
  # Sets the font strikethrough.
799
694
  # @param value [Boolean]
800
695
  # @return [Boolean]
801
696
  # @api public
802
697
  #: (bool value) -> bool
803
698
  def strike=(value)
804
- @font_props[:strike] = value
699
+ @font_props[:strike] = value ? true : false
805
700
  end
806
701
 
807
702
  # Returns whether strikethrough is enabled.
@@ -812,99 +707,78 @@ module Xlsxrb
812
707
  @font_props[:strike] ? true : false
813
708
  end
814
709
 
815
- # Gets or sets the vertical alignment of the font.
816
- # @param value [String, Symbol, Object] The alignment value ('superscript', 'subscript', 'baseline', :superscript, :subscript).
817
- # @return [String, self, nil]
710
+ # Gets the vertical alignment of the font.
711
+ # @return [String, nil]
818
712
  # @api public
819
- #: (?untyped value) -> (String | self | nil)
820
- def vert_align(value = OMITTED)
821
- return @font_props[:vert_align] if value.equal?(OMITTED)
822
-
823
- mapped = VERT_ALIGN_MAP[value.to_sym] || value.to_s
824
- @font_props[:vert_align] = mapped
825
- self
713
+ #: () -> String?
714
+ def vert_align
715
+ @font_props[:vert_align]
826
716
  end
827
717
 
828
- def vert_align=(value)
829
- vert_align(value)
830
- value
718
+ # Sets the vertical alignment of the font.
719
+ # @param val [String, Symbol]
720
+ # @return [Object]
721
+ # @api public
722
+ #: (untyped val) -> untyped
723
+ def vert_align=(val)
724
+ mapped = VERT_ALIGN_MAP[val.to_sym] || val.to_s
725
+ @font_props[:vert_align] = mapped
726
+ val
831
727
  end
832
728
 
833
729
  # Sets the font to superscript.
834
- # @param value [Boolean] Whether to apply superscript.
835
- # @return [self]
730
+ # @param val [Boolean]
731
+ # @return [Boolean]
836
732
  # @api public
837
- #: (?untyped) -> (self | bool)
838
- def superscript(value = OMITTED)
839
- if value.equal?(OMITTED)
840
- return superscript? unless @font_props[:vert_align].nil?
841
-
842
- Xlsxrb::Deprecation.warn("Calling StyleBuilder#superscript with zero arguments as a mutator is deprecated; pass true explicitly (e.g. superscript(true))", uplevel: 1)
843
- @font_props[:vert_align] = "superscript"
844
- return self
845
- end
846
-
847
- @font_props[:vert_align] = value ? "superscript" : "baseline"
848
- self
849
- end
850
-
851
- def superscript=(value)
852
- superscript(value)
853
- value
733
+ #: (untyped val) -> untyped
734
+ def superscript=(val)
735
+ @font_props[:vert_align] = val ? "superscript" : "baseline"
736
+ val
854
737
  end
855
738
 
739
+ # Returns whether superscript is enabled.
740
+ # @return [Boolean]
741
+ # @api public
742
+ #: () -> bool
856
743
  def superscript?
857
744
  @font_props[:vert_align] == "superscript"
858
745
  end
859
746
 
860
747
  # Sets the font to subscript.
861
- # @param value [Boolean] Whether to apply subscript.
862
- # @return [self]
748
+ # @param val [Boolean]
749
+ # @return [Boolean]
863
750
  # @api public
864
- #: (?untyped) -> (self | bool)
865
- def subscript(value = OMITTED)
866
- if value.equal?(OMITTED)
867
- return subscript? unless @font_props[:vert_align].nil?
868
-
869
- Xlsxrb::Deprecation.warn("Calling StyleBuilder#subscript with zero arguments as a mutator is deprecated; pass true explicitly (e.g. subscript(true))", uplevel: 1)
870
- @font_props[:vert_align] = "subscript"
871
- return self
872
- end
873
-
874
- @font_props[:vert_align] = value ? "subscript" : "baseline"
875
- self
876
- end
877
-
878
- def subscript=(value)
879
- subscript(value)
880
- value
751
+ #: (untyped val) -> untyped
752
+ def subscript=(val)
753
+ @font_props[:vert_align] = val ? "subscript" : "baseline"
754
+ val
881
755
  end
882
756
 
757
+ # Returns whether subscript is enabled.
758
+ # @return [Boolean]
759
+ # @api public
760
+ #: () -> bool
883
761
  def subscript?
884
762
  @font_props[:vert_align] == "subscript"
885
763
  end
764
+
886
765
  # --- Fill Properties ---
887
766
 
888
- # Sets the fill pattern.
889
- # @param pattern [String, Symbol] The pattern type.
767
+ # Sets or gets the fill pattern.
768
+ # @param pattern [String, Symbol, nil] The pattern type.
890
769
  # @param fg_color [String, Symbol, nil] The foreground color.
891
770
  # @param bg_color [String, Symbol, nil] The background color.
892
- # @return [self]
893
- # @api public
894
- # Configures fill properties.
895
- # @param pattern [String, Symbol] The pattern type.
896
- # @param fg_color [String, Symbol, nil] The foreground color.
897
- # @param bg_color [String, Symbol, nil] The background color.
898
- # @return [self]
771
+ # @return [String, Symbol, void, nil]
899
772
  # @api public
900
- #: (?untyped pattern, ?fg_color: String | Symbol | nil, ?bg_color: String | Symbol | nil) -> untyped
901
- def fill_pattern(pattern = OMITTED, fg_color: nil, bg_color: nil)
902
- return @fill_props[:pattern] if pattern.equal?(OMITTED)
773
+ #: () -> (String | Symbol | untyped)
774
+ #: (?untyped pattern, ?fg_color: String | Symbol | nil, ?bg_color: String | Symbol | nil) -> void
775
+ def fill_pattern(pattern = nil, fg_color: nil, bg_color: nil)
776
+ return @fill_props[:pattern] if pattern.nil? && fg_color.nil? && bg_color.nil?
903
777
 
904
- @fill_props[:pattern] = pattern
778
+ @fill_props[:pattern] = pattern if pattern
905
779
  @fill_props[:fg_color] = fg_color if fg_color
906
780
  @fill_props[:bg_color] = bg_color if bg_color
907
- self
781
+ nil
908
782
  end
909
783
 
910
784
  # Sets the fill pattern.
@@ -921,17 +795,12 @@ module Xlsxrb
921
795
  pattern
922
796
  end
923
797
 
924
- # Gets or sets a solid fill color.
925
- # @param color [String, Symbol, Object] The color.
926
- # @return [String, Symbol, self, nil]
798
+ # Gets a solid fill color.
799
+ # @return [String, nil]
927
800
  # @api public
928
- #: (?untyped color) -> (String | Symbol | self | nil)
929
- def fill_color(color = OMITTED)
930
- return @fill_props[:fg_color] if color.equal?(OMITTED)
931
-
932
- @fill_props[:pattern] = "solid"
933
- @fill_props[:fg_color] = resolve_color(color)
934
- self
801
+ #: () -> String?
802
+ def fill_color
803
+ @fill_props[:fg_color]
935
804
  end
936
805
 
937
806
  # Sets a solid fill color.
@@ -940,52 +809,74 @@ module Xlsxrb
940
809
  # @api public
941
810
  #: (String | Symbol color) -> (String | Symbol)
942
811
  def fill_color=(color)
943
- fill_color(color)
812
+ @fill_props[:pattern] = "solid"
813
+ @fill_props[:fg_color] = resolve_color(color)
944
814
  color
945
815
  end
946
816
 
947
- #: (?pattern: untyped, ?fg_color: String | Symbol | nil, ?bg_color: String | Symbol | nil) -> (self | Hash[Symbol, untyped])
948
- def fill(pattern: OMITTED, fg_color: nil, bg_color: nil)
949
- return @fill_props if pattern.equal?(OMITTED) && fg_color.nil? && bg_color.nil?
817
+ # Configures fill properties or returns current fill properties.
818
+ # @param pattern [String, Symbol, nil]
819
+ # @param fg_color [String, Symbol, nil]
820
+ # @param bg_color [String, Symbol, nil]
821
+ # @return [Hash, void]
822
+ # @api public
823
+ #: () -> Hash[Symbol, untyped]
824
+ #: (?pattern: untyped, ?fg_color: String | Symbol | nil, ?bg_color: String | Symbol | nil) -> void
825
+ def fill(pattern: nil, fg_color: nil, bg_color: nil)
826
+ return @fill_props if pattern.nil? && fg_color.nil? && bg_color.nil?
950
827
 
951
- pat = pattern.equal?(OMITTED) ? "solid" : pattern
828
+ pat = pattern || "solid"
952
829
  fill_pattern(pat, fg_color: resolve_color(fg_color), bg_color: resolve_color(bg_color))
830
+ nil
953
831
  end
954
832
 
833
+ # Sets fill options.
834
+ # @param opts [Hash, Object]
835
+ # @return [Object]
836
+ # @api public
837
+ #: (untyped opts) -> untyped
955
838
  def fill=(opts)
956
- fill(**opts)
839
+ if opts.is_a?(Hash)
840
+ fill(**opts)
841
+ else
842
+ fill(pattern: opts)
843
+ end
844
+ opts
957
845
  end
958
846
 
959
- # Sets a gradient fill.
960
- # @param type [String] The gradient type.
847
+ # Sets or gets a gradient fill.
848
+ # @param type [String, nil] The gradient type.
961
849
  # @param degree [Numeric, nil] The degree.
962
850
  # @param stops [Array] The gradient stops.
963
- # @return [self]
851
+ # @return [Hash, void, nil]
964
852
  # @api public
965
- #: (?type: untyped, ?degree: Numeric | nil, ?stops: Array[untyped]) -> (self | Hash[Symbol, untyped] | nil)
966
- def fill_gradient(type: OMITTED, degree: nil, stops: [])
967
- return @fill_props[:gradient] if type.equal?(OMITTED)
853
+ #: () -> Hash[Symbol, untyped]?
854
+ #: (?type: untyped, ?degree: Numeric | nil, ?stops: Array[untyped]) -> void
855
+ def fill_gradient(type: nil, degree: nil, stops: [])
856
+ return @fill_props[:gradient] if type.nil? && degree.nil? && stops.empty?
968
857
 
969
858
  @fill_props[:gradient] = {
970
859
  type: type,
971
860
  degree: degree,
972
861
  stops: stops
973
862
  }.compact
974
- self
863
+ nil
975
864
  end
976
865
 
977
866
  # --- Border Properties ---
978
867
 
979
- # Configures multiple border properties.
980
- # @param all [Hash, nil]
981
- # @param left [Hash, nil]
982
- # @param right [Hash, nil]
983
- # @param top [Hash, nil]
984
- # @param bottom [Hash, nil]
985
- # @param diagonal [Hash, nil]
986
- # @return [self]
987
- # @api public
988
- #: (?all: Hash[Symbol, untyped]?, ?left: Hash[Symbol, untyped]?, ?right: Hash[Symbol, untyped]?, ?top: Hash[Symbol, untyped]?, ?bottom: Hash[Symbol, untyped]?, ?diagonal: Hash[Symbol, untyped]?) -> (self | Hash[Symbol, untyped])
868
+ # Configures multiple border properties or returns current border properties.
869
+ #
870
+ # @param all [Hash, nil] Border options for all sides.
871
+ # @param left [Hash, nil] Options for left border.
872
+ # @param right [Hash, nil] Options for right border.
873
+ # @param top [Hash, nil] Options for top border.
874
+ # @param bottom [Hash, nil] Options for bottom border.
875
+ # @param diagonal [Hash, nil] Options for diagonal border.
876
+ # @return [Hash, void]
877
+ # @api public
878
+ #: () -> Hash[Symbol, untyped]
879
+ #: (?all: Hash[Symbol, untyped]?, ?left: Hash[Symbol, untyped]?, ?right: Hash[Symbol, untyped]?, ?top: Hash[Symbol, untyped]?, ?bottom: Hash[Symbol, untyped]?, ?diagonal: Hash[Symbol, untyped]?) -> void
989
880
  def border(all: nil, left: nil, right: nil, top: nil, bottom: nil, diagonal: nil)
990
881
  return @border_props if all.nil? && left.nil? && right.nil? && top.nil? && bottom.nil? && diagonal.nil?
991
882
 
@@ -995,75 +886,81 @@ module Xlsxrb
995
886
  border_top(**top) if top
996
887
  border_bottom(**bottom) if bottom
997
888
  border_diagonal(**diagonal) if diagonal
998
- self
889
+ nil
999
890
  end
1000
891
 
892
+ # Sets border options.
893
+ # @param opts [Hash]
894
+ # @return [Hash]
895
+ # @api public
896
+ #: (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
1001
897
  def border=(opts)
1002
898
  border(**opts)
899
+ opts
1003
900
  end
1004
901
 
1005
902
  # Sets all borders.
1006
903
  # @param style [String, Symbol, Integer] The border style.
1007
904
  # @param color [String, Symbol, nil] The color.
1008
- # @return [self]
905
+ # @return [void]
1009
906
  # @api public
1010
- #: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
907
+ #: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
1011
908
  def border_all(style: "thin", color: nil)
1012
- norm_style = self.class.normalize_border_style(style)&.to_s || style.to_s
909
+ norm_style = self.class.border_style!(style)
1013
910
  color_opt = color ? { color: resolve_color(color) } : {}
1014
911
  @border_props[:left] = { style: norm_style, **color_opt }
1015
912
  @border_props[:right] = { style: norm_style, **color_opt }
1016
913
  @border_props[:top] = { style: norm_style, **color_opt }
1017
914
  @border_props[:bottom] = { style: norm_style, **color_opt }
1018
- self
915
+ nil
1019
916
  end
1020
917
 
1021
918
  # Sets the left border.
1022
919
  # @param style [String, Symbol, Integer] The border style.
1023
920
  # @param color [String, Symbol, nil] The color.
1024
- # @return [self]
921
+ # @return [void]
1025
922
  # @api public
1026
- #: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
923
+ #: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
1027
924
  def border_left(style: "thin", color: nil)
1028
- norm_style = self.class.normalize_border_style(style)&.to_s || style.to_s
925
+ norm_style = self.class.border_style!(style)
1029
926
  @border_props[:left] = { style: norm_style, color: resolve_color(color) }.compact
1030
- self
927
+ nil
1031
928
  end
1032
929
 
1033
930
  # Sets the right border.
1034
931
  # @param style [String, Symbol, Integer] The border style.
1035
932
  # @param color [String, Symbol, nil] The color.
1036
- # @return [self]
933
+ # @return [void]
1037
934
  # @api public
1038
- #: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
935
+ #: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
1039
936
  def border_right(style: "thin", color: nil)
1040
- norm_style = self.class.normalize_border_style(style)&.to_s || style.to_s
937
+ norm_style = self.class.border_style!(style)
1041
938
  @border_props[:right] = { style: norm_style, color: resolve_color(color) }.compact
1042
- self
939
+ nil
1043
940
  end
1044
941
 
1045
942
  # Sets the top border.
1046
943
  # @param style [String, Symbol, Integer] The border style.
1047
944
  # @param color [String, Symbol, nil] The color.
1048
- # @return [self]
945
+ # @return [void]
1049
946
  # @api public
1050
- #: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
947
+ #: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
1051
948
  def border_top(style: "thin", color: nil)
1052
- norm_style = self.class.normalize_border_style(style)&.to_s || style.to_s
949
+ norm_style = self.class.border_style!(style)
1053
950
  @border_props[:top] = { style: norm_style, color: resolve_color(color) }.compact
1054
- self
951
+ nil
1055
952
  end
1056
953
 
1057
954
  # Sets the bottom border.
1058
955
  # @param style [String, Symbol, Integer] The border style.
1059
956
  # @param color [String, Symbol, nil] The color.
1060
- # @return [self]
957
+ # @return [void]
1061
958
  # @api public
1062
- #: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> self
959
+ #: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
1063
960
  def border_bottom(style: "thin", color: nil)
1064
- norm_style = self.class.normalize_border_style(style)&.to_s || style.to_s
961
+ norm_style = self.class.border_style!(style)
1065
962
  @border_props[:bottom] = { style: norm_style, color: resolve_color(color) }.compact
1066
- self
963
+ nil
1067
964
  end
1068
965
 
1069
966
  # rubocop:disable Naming/MethodParameterName
@@ -1072,15 +969,15 @@ module Xlsxrb
1072
969
  # @param color [String, Symbol, nil] The color.
1073
970
  # @param up [Boolean] Diagonal up.
1074
971
  # @param down [Boolean] Diagonal down.
1075
- # @return [self]
972
+ # @return [void]
1076
973
  # @api public
1077
- #: (?style: String | Symbol | Integer, ?color: String | Symbol | nil, ?up: bool, ?down: bool) -> self
974
+ #: (?style: String | Symbol | Integer, ?color: String | Symbol | nil, ?up: bool, ?down: bool) -> void
1078
975
  def border_diagonal(style: "thin", color: nil, up: false, down: false)
1079
- norm_style = self.class.normalize_border_style(style)&.to_s || style.to_s
976
+ norm_style = self.class.border_style!(style)
1080
977
  @border_props[:diagonal] = { style: norm_style, color: resolve_color(color) }.compact
1081
978
  @border_props[:diagonal_up] = true if up
1082
979
  @border_props[:diagonal_down] = true if down
1083
- self
980
+ nil
1084
981
  end
1085
982
  # rubocop:enable Naming/MethodParameterName
1086
983
 
@@ -1088,33 +985,34 @@ module Xlsxrb
1088
985
 
1089
986
  # Configures or returns alignment properties.
1090
987
  # When called with 0 arguments/keywords, returns the current alignment Hash.
1091
- # When called with keyword arguments, merges the properties and returns self.
988
+ # When called with keyword arguments, merges the properties and returns nil.
1092
989
  #
1093
- # @param horizontal [String, Symbol, nil]
1094
- # @param vertical [String, Symbol, nil]
1095
- # @param wrap_text [Boolean, nil]
1096
- # @param text_rotation [Integer, nil]
1097
- # @param indent [Integer, nil]
1098
- # @param shrink_to_fit [Boolean, nil]
1099
- # @param reading_order [Integer, nil]
1100
- # @param justify_last_line [Boolean, nil]
1101
- # @param relative_indent [Integer, nil]
1102
- # @return [Hash, self]
1103
- # @api public
1104
- #: (?horizontal: (String | Symbol)?, ?vertical: (String | Symbol)?, ?wrap_text: bool?, ?text_rotation: Integer?, ?indent: Integer?, ?shrink_to_fit: bool?, ?reading_order: Integer?, ?justify_last_line: bool?, ?relative_indent: Integer?) -> (Hash[Symbol, untyped] | self)
990
+ # @param horizontal [String, Symbol, nil] Horizontal alignment (:left, :center, :right, :fill, :justify, etc.).
991
+ # @param vertical [String, Symbol, nil] Vertical alignment (:top, :center, :bottom, :justify, :distributed).
992
+ # @param wrap_text [Boolean, nil] Whether to wrap text within the cell.
993
+ # @param text_rotation [Integer, nil] Text rotation in degrees (0-180 or 255 for vertical).
994
+ # @param indent [Integer, nil] Indentation level (0-250).
995
+ # @param shrink_to_fit [Boolean, nil] Whether to shrink text to fit cell width.
996
+ # @param reading_order [Integer, nil] Reading order (0: context, 1: left-to-right, 2: right-to-left).
997
+ # @param justify_last_line [Boolean, nil] Whether to justify the last line of text.
998
+ # @param relative_indent [Integer, nil] Relative indentation level.
999
+ # @return [Hash, void]
1000
+ # @api public
1001
+ #: () -> Hash[Symbol, untyped]
1002
+ #: (?horizontal: (String | Symbol)?, ?vertical: (String | Symbol)?, ?wrap_text: bool?, ?text_rotation: Integer?, ?indent: Integer?, ?shrink_to_fit: bool?, ?reading_order: Integer?, ?justify_last_line: bool?, ?relative_indent: Integer?) -> void
1105
1003
  def alignment(horizontal: nil, vertical: nil, wrap_text: nil, text_rotation: nil, indent: nil, shrink_to_fit: nil, reading_order: nil, justify_last_line: nil, relative_indent: nil)
1106
1004
  return @alignment if horizontal.nil? && vertical.nil? && wrap_text.nil? && text_rotation.nil? && indent.nil? && shrink_to_fit.nil? && reading_order.nil? && justify_last_line.nil? && relative_indent.nil?
1107
1005
 
1108
- align_horizontal(horizontal) unless horizontal.nil?
1109
- align_vertical(vertical) unless vertical.nil?
1110
- wrap_text(wrap_text) unless wrap_text.nil?
1111
- text_rotation(text_rotation) unless text_rotation.nil?
1112
- indent(indent) unless indent.nil?
1113
- shrink_to_fit(shrink_to_fit) unless shrink_to_fit.nil?
1006
+ self.align_horizontal = horizontal unless horizontal.nil?
1007
+ self.align_vertical = vertical unless vertical.nil?
1008
+ self.wrap_text = wrap_text unless wrap_text.nil?
1009
+ self.text_rotation = text_rotation unless text_rotation.nil?
1010
+ self.indent = indent unless indent.nil?
1011
+ self.shrink_to_fit = shrink_to_fit unless shrink_to_fit.nil?
1114
1012
  @alignment[:reading_order] = reading_order unless reading_order.nil?
1115
1013
  @alignment[:justify_last_line] = justify_last_line unless justify_last_line.nil?
1116
1014
  @alignment[:relative_indent] = relative_indent unless relative_indent.nil?
1117
- self
1015
+ nil
1118
1016
  end
1119
1017
 
1120
1018
  # Sets alignment options.
@@ -1128,16 +1026,12 @@ module Xlsxrb
1128
1026
  opts
1129
1027
  end
1130
1028
 
1131
- # Gets or sets horizontal alignment.
1132
- # @param value [String, Symbol, Object] The alignment.
1133
- # @return [String, Symbol, self, nil]
1029
+ # Gets horizontal alignment.
1030
+ # @return [String, Symbol, nil]
1134
1031
  # @api public
1135
- #: (?untyped value) -> (String | Symbol | self | nil)
1136
- def align_horizontal(value = OMITTED)
1137
- return @alignment[:horizontal] if value.equal?(OMITTED)
1138
-
1139
- @alignment[:horizontal] = value
1140
- self
1032
+ #: () -> (String | Symbol | nil)
1033
+ def align_horizontal
1034
+ @alignment[:horizontal]
1141
1035
  end
1142
1036
 
1143
1037
  # Sets horizontal alignment.
@@ -1149,16 +1043,12 @@ module Xlsxrb
1149
1043
  @alignment[:horizontal] = value
1150
1044
  end
1151
1045
 
1152
- # Gets or sets vertical alignment.
1153
- # @param value [String, Symbol, Object] The alignment.
1154
- # @return [String, Symbol, self, nil]
1046
+ # Gets vertical alignment.
1047
+ # @return [String, Symbol, nil]
1155
1048
  # @api public
1156
- #: (?untyped value) -> (String | Symbol | self | nil)
1157
- def align_vertical(value = OMITTED)
1158
- return @alignment[:vertical] if value.equal?(OMITTED)
1159
-
1160
- @alignment[:vertical] = value
1161
- self
1049
+ #: () -> (String | Symbol | nil)
1050
+ def align_vertical
1051
+ @alignment[:vertical]
1162
1052
  end
1163
1053
 
1164
1054
  # Sets vertical alignment.
@@ -1170,31 +1060,13 @@ module Xlsxrb
1170
1060
  @alignment[:vertical] = value
1171
1061
  end
1172
1062
 
1173
- # Sets text wrapping.
1174
- # @param value [Boolean] Whether to wrap text.
1175
- # @return [self]
1176
- # @api public
1177
- #: (?untyped) -> (self | bool)
1178
- def wrap_text(value = OMITTED)
1179
- if value.equal?(OMITTED)
1180
- return wrap_text? unless @alignment[:wrap_text].nil?
1181
-
1182
- Xlsxrb::Deprecation.warn("Calling StyleBuilder#wrap_text with zero arguments as a mutator is deprecated; pass true explicitly (e.g. wrap_text(true))", uplevel: 1)
1183
- @alignment[:wrap_text] = true
1184
- return self
1185
- end
1186
-
1187
- @alignment[:wrap_text] = value ? true : false
1188
- self
1189
- end
1190
-
1191
1063
  # Sets text wrapping.
1192
1064
  # @param value [Boolean]
1193
1065
  # @return [Boolean]
1194
1066
  # @api public
1195
1067
  #: (bool value) -> bool
1196
1068
  def wrap_text=(value)
1197
- @alignment[:wrap_text] = value
1069
+ @alignment[:wrap_text] = value ? true : false
1198
1070
  end
1199
1071
 
1200
1072
  # Returns whether text wrapping is enabled.
@@ -1205,31 +1077,13 @@ module Xlsxrb
1205
1077
  @alignment[:wrap_text] ? true : false
1206
1078
  end
1207
1079
 
1208
- # Sets shrink to fit.
1209
- # @param value [Boolean] Whether to shrink text.
1210
- # @return [self]
1211
- # @api public
1212
- #: (?untyped) -> (self | bool)
1213
- def shrink_to_fit(value = OMITTED)
1214
- if value.equal?(OMITTED)
1215
- return shrink_to_fit? unless @alignment[:shrink_to_fit].nil?
1216
-
1217
- Xlsxrb::Deprecation.warn("Calling StyleBuilder#shrink_to_fit with zero arguments as a mutator is deprecated; pass true explicitly (e.g. shrink_to_fit(true))", uplevel: 1)
1218
- @alignment[:shrink_to_fit] = true
1219
- return self
1220
- end
1221
-
1222
- @alignment[:shrink_to_fit] = value ? true : false
1223
- self
1224
- end
1225
-
1226
1080
  # Sets shrink to fit.
1227
1081
  # @param value [Boolean]
1228
1082
  # @return [Boolean]
1229
1083
  # @api public
1230
1084
  #: (bool value) -> bool
1231
1085
  def shrink_to_fit=(value)
1232
- @alignment[:shrink_to_fit] = value
1086
+ @alignment[:shrink_to_fit] = value ? true : false
1233
1087
  end
1234
1088
 
1235
1089
  # Returns whether shrink to fit is enabled.
@@ -1240,16 +1094,12 @@ module Xlsxrb
1240
1094
  @alignment[:shrink_to_fit] ? true : false
1241
1095
  end
1242
1096
 
1243
- # Gets or sets text rotation.
1244
- # @param value [Numeric, Object] The rotation angle.
1245
- # @return [Numeric, self, nil]
1097
+ # Gets text rotation.
1098
+ # @return [Numeric, nil]
1246
1099
  # @api public
1247
- #: (?untyped value) -> (Numeric | self | nil)
1248
- def text_rotation(value = OMITTED)
1249
- return @alignment[:text_rotation] if value.equal?(OMITTED)
1250
-
1251
- @alignment[:text_rotation] = value
1252
- self
1100
+ #: () -> (Numeric | nil)
1101
+ def text_rotation
1102
+ @alignment[:text_rotation]
1253
1103
  end
1254
1104
 
1255
1105
  # Sets text rotation.
@@ -1261,16 +1111,12 @@ module Xlsxrb
1261
1111
  @alignment[:text_rotation] = value
1262
1112
  end
1263
1113
 
1264
- # Gets or sets text indent.
1265
- # @param value [Numeric, Object] The indent level.
1266
- # @return [Numeric, self, nil]
1114
+ # Gets text indent.
1115
+ # @return [Integer, nil]
1267
1116
  # @api public
1268
- #: (?untyped value) -> (Numeric | self | nil)
1269
- def indent(value = OMITTED)
1270
- return @alignment[:indent] if value.equal?(OMITTED)
1271
-
1272
- @alignment[:indent] = value.to_i
1273
- self
1117
+ #: () -> (Integer | nil)
1118
+ def indent
1119
+ @alignment[:indent]
1274
1120
  end
1275
1121
 
1276
1122
  # Sets text indent.
@@ -1286,19 +1132,20 @@ module Xlsxrb
1286
1132
 
1287
1133
  # Configures or returns cell protection properties.
1288
1134
  # When called with 0 arguments/keywords, returns the current protection Hash.
1289
- # When called with keyword arguments, merges the properties and returns self.
1135
+ # When called with keyword arguments, merges the properties and returns nil.
1290
1136
  #
1291
1137
  # @param locked [Boolean, nil]
1292
1138
  # @param hidden [Boolean, nil]
1293
- # @return [Hash, self]
1139
+ # @return [Hash, void]
1294
1140
  # @api public
1295
- #: (?locked: bool?, ?hidden: bool?) -> (Hash[Symbol, untyped] | self)
1141
+ #: () -> Hash[Symbol, untyped]
1142
+ #: (?locked: bool?, ?hidden: bool?) -> void
1296
1143
  def protection(locked: nil, hidden: nil)
1297
1144
  return @protection if locked.nil? && hidden.nil?
1298
1145
 
1299
- @protection[:locked] = locked unless locked.nil?
1300
- @protection[:hidden] = hidden unless hidden.nil?
1301
- self
1146
+ self.locked = locked unless locked.nil?
1147
+ self.hidden = hidden unless hidden.nil?
1148
+ nil
1302
1149
  end
1303
1150
 
1304
1151
  # Sets protection options.
@@ -1312,25 +1159,6 @@ module Xlsxrb
1312
1159
  opts
1313
1160
  end
1314
1161
 
1315
- # Sets whether the cell is locked.
1316
- #
1317
- # @param value [Boolean]
1318
- # @return [self]
1319
- # @api public
1320
- #: (?untyped value) -> (self | bool)
1321
- def locked(value = OMITTED)
1322
- if value.equal?(OMITTED)
1323
- return locked? unless @protection[:locked].nil?
1324
-
1325
- Xlsxrb::Deprecation.warn("Calling StyleBuilder#locked with zero arguments as a mutator is deprecated; pass true explicitly (e.g. locked(true))", uplevel: 1)
1326
- @protection[:locked] = true
1327
- return self
1328
- end
1329
-
1330
- @protection[:locked] = value ? true : false
1331
- self
1332
- end
1333
-
1334
1162
  # Sets whether the cell is locked.
1335
1163
  #
1336
1164
  # @param value [Boolean]
@@ -1338,7 +1166,7 @@ module Xlsxrb
1338
1166
  # @api public
1339
1167
  #: (bool value) -> bool
1340
1168
  def locked=(value)
1341
- @protection[:locked] = value
1169
+ @protection[:locked] = value ? true : false
1342
1170
  end
1343
1171
 
1344
1172
  # Returns whether the cell is locked.
@@ -1349,25 +1177,6 @@ module Xlsxrb
1349
1177
  @protection[:locked] != false
1350
1178
  end
1351
1179
 
1352
- # Sets whether the cell formula is hidden.
1353
- #
1354
- # @param value [Boolean]
1355
- # @return [self]
1356
- # @api public
1357
- #: (?untyped value) -> (self | bool)
1358
- def hidden(value = OMITTED)
1359
- if value.equal?(OMITTED)
1360
- return hidden? unless @protection[:hidden].nil?
1361
-
1362
- Xlsxrb::Deprecation.warn("Calling StyleBuilder#hidden with zero arguments as a mutator is deprecated; pass true explicitly (e.g. hidden(true))", uplevel: 1)
1363
- @protection[:hidden] = true
1364
- return self
1365
- end
1366
-
1367
- @protection[:hidden] = value ? true : false
1368
- self
1369
- end
1370
-
1371
1180
  # Sets whether the cell formula is hidden.
1372
1181
  #
1373
1182
  # @param value [Boolean]
@@ -1375,7 +1184,7 @@ module Xlsxrb
1375
1184
  # @api public
1376
1185
  #: (bool value) -> bool
1377
1186
  def hidden=(value)
1378
- @protection[:hidden] = value
1187
+ @protection[:hidden] = value ? true : false
1379
1188
  end
1380
1189
 
1381
1190
  # Returns whether the cell formula is hidden.
@@ -1388,18 +1197,12 @@ module Xlsxrb
1388
1197
 
1389
1198
  # --- Number Format ---
1390
1199
 
1391
- # Sets or gets the number format.
1392
- # @param num_fmt_id [String, Integer, nil] The format id or format string.
1393
- # @return [String, Integer, self, nil]
1200
+ # Gets the number format.
1201
+ # @return [String, Integer, nil]
1394
1202
  # @api public
1395
- #: (?String | Integer | nil num_fmt_id) -> (String | Integer | self | nil)
1396
- def number_format(num_fmt_id = nil)
1397
- if num_fmt_id.nil?
1398
- @num_fmt_id
1399
- else
1400
- @num_fmt_id = num_fmt_id
1401
- self
1402
- end
1203
+ #: () -> (String | Integer | nil)
1204
+ def number_format
1205
+ @num_fmt_id
1403
1206
  end
1404
1207
 
1405
1208
  # Sets the number format.
@@ -1411,56 +1214,6 @@ module Xlsxrb
1411
1214
  @num_fmt_id = num_fmt_id
1412
1215
  end
1413
1216
 
1414
- # Sets or gets the number format ID.
1415
- # @deprecated Use {#number_format} instead. Will be removed in 0.2.0.
1416
- # @param id [String, Integer, nil]
1417
- # @return [String, Integer, self, nil]
1418
- # @api public
1419
- #: (?String | Integer | nil id) -> (String | Integer | self | nil)
1420
- def number_format_id(id = nil)
1421
- warn "[Xlsxrb DEPRECATION] StyleBuilder#number_format_id is deprecated; use #number_format instead.", uplevel: 1
1422
- number_format(id)
1423
- end
1424
-
1425
- # Sets the number format ID.
1426
- # @deprecated Use {#number_format=} instead. Will be removed in 0.2.0.
1427
- # @param id [String, Integer]
1428
- # @return [String, Integer]
1429
- # @api public
1430
- #: (String | Integer id) -> (String | Integer)
1431
- def number_format_id=(id)
1432
- warn "[Xlsxrb DEPRECATION] StyleBuilder#number_format_id= is deprecated; use #number_format= instead.", uplevel: 1
1433
- @num_fmt_id = id
1434
- end
1435
-
1436
- # @deprecated Use {#number_format} instead. Will be removed in 0.2.0.
1437
- #: (?String | Integer | nil num_fmt_id) -> (String | Integer | self | nil)
1438
- def num_fmt(num_fmt_id = nil)
1439
- warn "[DEPRECATION] #num_fmt is deprecated; use #number_format instead.", uplevel: 1
1440
- number_format(num_fmt_id)
1441
- end
1442
-
1443
- # @deprecated Use {#number_format=} instead. Will be removed in 0.2.0.
1444
- #: (String | Integer num_fmt_id) -> (String | Integer)
1445
- def num_fmt=(num_fmt_id)
1446
- warn "[DEPRECATION] #num_fmt= is deprecated; use #number_format= instead.", uplevel: 1
1447
- self.number_format = num_fmt_id
1448
- end
1449
-
1450
- # @deprecated Use {#number_format_id} instead. Will be removed in 0.2.0.
1451
- #: (?String | Integer | nil id) -> (String | Integer | self | nil)
1452
- def num_fmt_id(id = nil)
1453
- warn "[DEPRECATION] #num_fmt_id is deprecated; use #number_format_id instead.", uplevel: 1
1454
- number_format_id(id)
1455
- end
1456
-
1457
- # @deprecated Use {#number_format_id=} instead. Will be removed in 0.2.0.
1458
- #: (String | Integer id) -> (String | Integer)
1459
- def num_fmt_id=(id)
1460
- warn "[DEPRECATION] #num_fmt_id= is deprecated; use #number_format_id= instead.", uplevel: 1
1461
- self.number_format_id = id
1462
- end
1463
-
1464
1217
  # Register this style with the given Writer, returning the style_id.
1465
1218
  # writer:: Xlsxrb::Ooxml::Writer instance
1466
1219
  #: (untyped writer) -> Integer
@@ -1493,6 +1246,36 @@ module Xlsxrb
1493
1246
 
1494
1247
  private
1495
1248
 
1249
+ # Raises ArgumentError for option keys #apply_options! does not know, and for a nested
1250
+ # group (font:, fill:, ...) given together with its flat keys, which would be ignored.
1251
+ #: (Hash[Symbol, untyped] opts) -> void
1252
+ def check_options!(opts)
1253
+ opts.each_key { |key| raise ArgumentError, unknown_option_message(key, OPTION_KEYS, "style option") unless OPTION_KEYS.include?(key) }
1254
+
1255
+ NESTED_OPTION_KEYS.each do |group, allowed|
1256
+ nested = opts[group]
1257
+ next unless nested.is_a?(Hash)
1258
+
1259
+ nested.each_key { |key| raise ArgumentError, unknown_option_message(key, allowed, "#{group}: option") unless allowed.include?(key) }
1260
+ end
1261
+
1262
+ FLAT_KEYS_BY_GROUP.each do |group, flat_keys|
1263
+ next unless opts.key?(group)
1264
+
1265
+ mixed = flat_keys.select { |key| opts.key?(key) }
1266
+ next if mixed.empty?
1267
+
1268
+ raise ArgumentError, "Give #{group} options either as #{group}: { ... } or as flat keys, not both (got #{group}: and #{mixed.map(&:inspect).join(", ")})"
1269
+ end
1270
+ end
1271
+
1272
+ def unknown_option_message(key, allowed, kind)
1273
+ suggestion = DslHelpers.closest_name(key, allowed)
1274
+ message = "Unknown #{kind} #{key.inspect}"
1275
+ message << "; did you mean #{suggestion.to_sym.inspect}?" if suggestion
1276
+ message << " (valid: #{allowed.map(&:inspect).join(", ")})"
1277
+ end
1278
+
1496
1279
  def resolve_color(color)
1497
1280
  self.class.resolve_color(color)
1498
1281
  end