caxlsx 4.1.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -12
  3. data/README.md +7 -1
  4. data/Rakefile +2 -9
  5. data/lib/axlsx/content_type/abstract_content_type.rb +2 -2
  6. data/lib/axlsx/content_type/content_type.rb +3 -3
  7. data/lib/axlsx/drawing/area_chart.rb +3 -3
  8. data/lib/axlsx/drawing/area_series.rb +2 -2
  9. data/lib/axlsx/drawing/ax_data_source.rb +1 -1
  10. data/lib/axlsx/drawing/axes.rb +1 -1
  11. data/lib/axlsx/drawing/axis.rb +1 -1
  12. data/lib/axlsx/drawing/bar_3D_chart.rb +14 -4
  13. data/lib/axlsx/drawing/bar_chart.rb +14 -4
  14. data/lib/axlsx/drawing/bar_series.rb +2 -2
  15. data/lib/axlsx/drawing/bubble_chart.rb +2 -2
  16. data/lib/axlsx/drawing/bubble_series.rb +2 -2
  17. data/lib/axlsx/drawing/cat_axis.rb +3 -3
  18. data/lib/axlsx/drawing/chart.rb +1 -0
  19. data/lib/axlsx/drawing/d_lbls.rb +5 -4
  20. data/lib/axlsx/drawing/drawing.rb +50 -50
  21. data/lib/axlsx/drawing/hyperlink.rb +1 -1
  22. data/lib/axlsx/drawing/line_3D_chart.rb +3 -3
  23. data/lib/axlsx/drawing/line_chart.rb +3 -3
  24. data/lib/axlsx/drawing/line_series.rb +2 -2
  25. data/lib/axlsx/drawing/num_val.rb +1 -1
  26. data/lib/axlsx/drawing/pic.rb +4 -4
  27. data/lib/axlsx/drawing/pie_3D_chart.rb +2 -2
  28. data/lib/axlsx/drawing/pie_chart.rb +2 -2
  29. data/lib/axlsx/drawing/pie_series.rb +2 -2
  30. data/lib/axlsx/drawing/scatter_chart.rb +2 -2
  31. data/lib/axlsx/drawing/scatter_series.rb +2 -2
  32. data/lib/axlsx/drawing/ser_axis.rb +3 -3
  33. data/lib/axlsx/drawing/two_cell_anchor.rb +1 -1
  34. data/lib/axlsx/drawing/val_axis.rb +2 -2
  35. data/lib/axlsx/drawing/vml_shape.rb +1 -1
  36. data/lib/axlsx/package.rb +10 -12
  37. data/lib/axlsx/rels/relationship.rb +2 -2
  38. data/lib/axlsx/rels/relationships.rb +2 -2
  39. data/lib/axlsx/stylesheet/border_pr.rb +2 -1
  40. data/lib/axlsx/stylesheet/cell_alignment.rb +1 -1
  41. data/lib/axlsx/stylesheet/cell_style.rb +1 -1
  42. data/lib/axlsx/stylesheet/color.rb +2 -2
  43. data/lib/axlsx/stylesheet/font.rb +1 -1
  44. data/lib/axlsx/stylesheet/gradient_fill.rb +1 -1
  45. data/lib/axlsx/stylesheet/pattern_fill.rb +1 -0
  46. data/lib/axlsx/stylesheet/styles.rb +27 -31
  47. data/lib/axlsx/stylesheet/xf.rb +2 -1
  48. data/lib/axlsx/util/accessors.rb +1 -1
  49. data/lib/axlsx/util/buffered_zip_output_stream.rb +2 -2
  50. data/lib/axlsx/util/constants.rb +2 -2
  51. data/lib/axlsx/util/serialized_attributes.rb +2 -2
  52. data/lib/axlsx/util/simple_typed_list.rb +26 -14
  53. data/lib/axlsx/util/storage.rb +3 -3
  54. data/lib/axlsx/util/validators.rb +2 -2
  55. data/lib/axlsx/version.rb +1 -1
  56. data/lib/axlsx/workbook/defined_name.rb +2 -1
  57. data/lib/axlsx/workbook/shared_strings_table.rb +3 -3
  58. data/lib/axlsx/workbook/workbook.rb +61 -61
  59. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +4 -4
  60. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +1 -1
  61. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +4 -4
  62. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +1 -1
  63. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +2 -2
  64. data/lib/axlsx/workbook/worksheet/border_creator.rb +4 -4
  65. data/lib/axlsx/workbook/worksheet/cell.rb +10 -10
  66. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +1 -1
  67. data/lib/axlsx/workbook/worksheet/col.rb +23 -9
  68. data/lib/axlsx/workbook/worksheet/comment.rb +2 -2
  69. data/lib/axlsx/workbook/worksheet/comments.rb +1 -1
  70. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
  71. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
  72. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +2 -2
  73. data/lib/axlsx/workbook/worksheet/data_validation.rb +1 -1
  74. data/lib/axlsx/workbook/worksheet/data_validations.rb +2 -2
  75. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +2 -2
  76. data/lib/axlsx/workbook/worksheet/dimension.rb +1 -1
  77. data/lib/axlsx/workbook/worksheet/header_footer.rb +1 -1
  78. data/lib/axlsx/workbook/worksheet/icon_set.rb +1 -1
  79. data/lib/axlsx/workbook/worksheet/outline_pr.rb +1 -1
  80. data/lib/axlsx/workbook/worksheet/page_setup.rb +2 -2
  81. data/lib/axlsx/workbook/worksheet/pane.rb +1 -0
  82. data/lib/axlsx/workbook/worksheet/pivot_table.rb +30 -6
  83. data/lib/axlsx/workbook/worksheet/print_options.rb +1 -0
  84. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +1 -1
  85. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +1 -0
  86. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +1 -1
  87. data/lib/axlsx/workbook/worksheet/table_style_info.rb +2 -1
  88. data/lib/axlsx/workbook/worksheet/worksheet.rb +10 -12
  89. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -4
  90. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
  91. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +2 -1
  92. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +1 -1
  93. data/lib/axlsx.rb +44 -30
  94. data/lib/caxlsx.rb +1 -1
  95. metadata +7 -10
@@ -21,7 +21,7 @@ module Axlsx
21
21
  alias :== :equal?
22
22
  alias :eql? :equal?
23
23
 
24
- # Creats a new typed list
24
+ # Creates a new typed list
25
25
  # @param [Array, Class] type An array of Class objects or a single Class object
26
26
  # @param [String] serialize_as The tag name to use in serialization
27
27
  # @raise [ArgumentError] if all members of type are not Class objects
@@ -57,7 +57,7 @@ module Axlsx
57
57
  # Transposes the list (without blowing up like ruby does)
58
58
  # any non populated cell in the matrix will be a nil value
59
59
  def transpose
60
- return clone if size.zero?
60
+ return clone if size == 0
61
61
 
62
62
  row_count = size
63
63
  max_column_count = map { |row| row.cells.size }.max
@@ -90,21 +90,24 @@ module Axlsx
90
90
  self
91
91
  end
92
92
 
93
- # join operator
94
- # @param [Array] other the array to join
93
+ # Appends the elements of +others+ to self.
94
+ # @param [Array<Array>] others one or more arrays to join
95
95
  # @raise [ArgumentError] if any of the values being joined are not
96
96
  # one of the allowed types
97
97
  # @return [SimpleTypedList]
98
- def +(other)
99
- other.each do |item|
100
- self << item
98
+ def concat(*others)
99
+ others.each do |other|
100
+ other.each do |item|
101
+ self << item
102
+ end
101
103
  end
102
- super
104
+ self
103
105
  end
104
106
 
105
- # Concat operator
107
+ # Pushes the given object on to the end of this array and returns the index
108
+ # of the item added.
106
109
  # @param [Any] v the data to be added
107
- # @raise [ArgumentError] if the value being added is not one fo the allowed types
110
+ # @raise [ArgumentError] if the value being added is not one of the allowed types
108
111
  # @return [Integer] returns the index of the item added.
109
112
  def <<(v)
110
113
  DataTypeValidator.validate :SimpleTypedList_push, @allowed_types, v
@@ -112,7 +115,17 @@ module Axlsx
112
115
  size - 1
113
116
  end
114
117
 
115
- alias :push :<<
118
+ # Pushes the given object(s) on to the end of this array. This expression
119
+ # returns the array itself, so several appends may be chained together.
120
+ # @param [Any] values the data to be added
121
+ # @raise [ArgumentError] if any of the values being joined are not
122
+ # @return [SimpleTypedList]
123
+ def push(*values)
124
+ values.each do |value|
125
+ self << value
126
+ end
127
+ self
128
+ end
116
129
 
117
130
  # delete the item from the list
118
131
  # @param [Any] v The item to be deleted.
@@ -147,7 +160,7 @@ module Axlsx
147
160
  super
148
161
  end
149
162
 
150
- # inserts an item at the index specfied
163
+ # inserts an item at the index specified
151
164
  # @param [Integer] index
152
165
  # @param [Any] v
153
166
  # @raise [ArgumentError] if the index is protected by locking
@@ -170,8 +183,7 @@ module Axlsx
170
183
  end
171
184
 
172
185
  def to_xml_string(str = +'')
173
- classname = @allowed_types[0].name.split('::').last
174
- el_name = serialize_as.to_s || (classname[0, 1].downcase + classname[1..])
186
+ el_name = serialize_as.to_s
175
187
  str << '<' << el_name << ' count="' << size.to_s << '">'
176
188
  each { |item| item.to_xml_string(str) }
177
189
  str << '</' << el_name << '>'
@@ -85,16 +85,16 @@ module Axlsx
85
85
  # @return [Integer] sector
86
86
  attr_accessor :sector
87
87
 
88
- # The 0 based index in the directoies chain for this the left sibling of this storage.
88
+ # The 0 based index in the directories chain for this the left sibling of this storage.
89
89
 
90
90
  # @return [Integer] left
91
91
  attr_accessor :left
92
92
 
93
- # The 0 based index in the directoies chain for this the right sibling of this storage.
93
+ # The 0 based index in the directories chain for this the right sibling of this storage.
94
94
  # @return [Integer] right
95
95
  attr_accessor :right
96
96
 
97
- # The 0 based index in the directoies chain for the child of this storage.
97
+ # The 0 based index in the directories chain for the child of this storage.
98
98
  # @return [Integer] child
99
99
  attr_accessor :child
100
100
 
@@ -9,7 +9,7 @@ module Axlsx
9
9
  # @param [Any] v The value to be validated
10
10
  # @raise [ArgumentError] Raised if the value provided is not in the list of choices.
11
11
  # @return [Boolean] true if validation succeeds.
12
- def self.validate(name, choices, v)
12
+ def self.validate(name, choices, v) # rubocop:disable Naming/PredicateMethod
13
13
  raise ArgumentError, format(ERR_RESTRICTION, v.to_s, name, choices.inspect) unless choices.include?(v)
14
14
 
15
15
  true
@@ -81,7 +81,7 @@ module Axlsx
81
81
  raise ArgumentError, format(ERR_ANGLE, v.inspect) unless v.to_i >= -5400000 && v.to_i <= 5400000
82
82
  end
83
83
 
84
- # Validates an unsigned intger
84
+ # Validates an unsigned integer
85
85
  UINT_VALIDATOR = ->(arg) { arg.respond_to?(:>=) && arg >= 0 }
86
86
 
87
87
  # Requires that the value is a Integer and is greater or equal to 0
data/lib/axlsx/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Axlsx
4
4
  # The current version
5
- VERSION = "4.1.0"
5
+ VERSION = "4.3.0"
6
6
  end
@@ -22,7 +22,7 @@
22
22
  # <xsd:attribute name="shortcutKey" type="s:ST_Xstring" use="optional"/>
23
23
  # <xsd:attribute name="publishToServer" type="xsd:boolean" use="optional" default="false"/>
24
24
  # <xsd:attribute name="workbookParameter" type="xsd:boolean" use="optional" default="false"/>
25
- # </xsd:extenstion>
25
+ # </xsd:extension>
26
26
  # </xsd:simpleContent>
27
27
 
28
28
  module Axlsx
@@ -54,6 +54,7 @@ module Axlsx
54
54
  include Axlsx::SerializedAttributes
55
55
  include Axlsx::OptionsParser
56
56
  include Axlsx::Accessors
57
+
57
58
  # creates a new DefinedName.
58
59
  # @param [String] formula - the formula the defined name references
59
60
  # @param [Hash] options - A hash of key/value pairs that will be mapped to this instances attributes.
@@ -7,7 +7,7 @@ module Axlsx
7
7
  # As a developer, you should never need to directly work against this class. Simply set 'use_shared_strings'
8
8
  # on the package or workbook to generate a package that uses the shared strings table instead of inline strings.
9
9
  # @note Serialization performance is affected by using this serialization method so if you do not need interoperability
10
- # it is recomended that you use the default inline string method of serialization.
10
+ # it is recommended that you use the default inline string method of serialization.
11
11
  class SharedStringsTable
12
12
  # The total number of strings in the workbook including duplicates
13
13
  # Empty cells are treated as blank strings
@@ -29,7 +29,7 @@ module Axlsx
29
29
  # @see Workbook#xml_space
30
30
  attr_reader :xml_space
31
31
 
32
- # Creates a new Shared Strings Table agains an array of cells
32
+ # Creates a new Shared Strings Table against an array of cells
33
33
  # @param [Array] cells This is an array of all of the cells in the workbook
34
34
  # @param [Symbol] xml_space The xml:space behavior for the shared string table.
35
35
  def initialize(cells, xml_space = :preserve)
@@ -54,7 +54,7 @@ module Axlsx
54
54
 
55
55
  private
56
56
 
57
- # Interate over all of the cells in the array.
57
+ # Iterate over all of the cells in the array.
58
58
  # if our unique cells array does not contain a sharable cell,
59
59
  # add the cell to our unique cells array and set the ssti attribute on the index of this cell in the shared strings table
60
60
  # if a sharable cell already exists in our unique_cells array, set the ssti attribute of the cell and move on.
@@ -1,67 +1,67 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Axlsx
4
- require 'axlsx/workbook/worksheet/sheet_calc_pr'
5
- require 'axlsx/workbook/worksheet/auto_filter/auto_filter'
6
- require 'axlsx/workbook/worksheet/date_time_converter'
7
- require 'axlsx/workbook/worksheet/protected_range'
8
- require 'axlsx/workbook/worksheet/protected_ranges'
9
- require 'axlsx/workbook/worksheet/rich_text_run'
10
- require 'axlsx/workbook/worksheet/rich_text'
11
- require 'axlsx/workbook/worksheet/cell_serializer'
12
- require 'axlsx/workbook/worksheet/cell'
13
- require 'axlsx/workbook/worksheet/page_margins'
14
- require 'axlsx/workbook/worksheet/page_set_up_pr'
15
- require 'axlsx/workbook/worksheet/outline_pr'
16
- require 'axlsx/workbook/worksheet/page_setup'
17
- require 'axlsx/workbook/worksheet/header_footer'
18
- require 'axlsx/workbook/worksheet/print_options'
19
- require 'axlsx/workbook/worksheet/cfvo'
20
- require 'axlsx/workbook/worksheet/cfvos'
21
- require 'axlsx/workbook/worksheet/color_scale'
22
- require 'axlsx/workbook/worksheet/data_bar'
23
- require 'axlsx/workbook/worksheet/icon_set'
24
- require 'axlsx/workbook/worksheet/conditional_formatting'
25
- require 'axlsx/workbook/worksheet/conditional_formatting_rule'
26
- require 'axlsx/workbook/worksheet/conditional_formattings'
27
- require 'axlsx/workbook/worksheet/row'
28
- require 'axlsx/workbook/worksheet/col'
29
- require 'axlsx/workbook/worksheet/cols'
30
- require 'axlsx/workbook/worksheet/comments'
31
- require 'axlsx/workbook/worksheet/comment'
32
- require 'axlsx/workbook/worksheet/merged_cells'
33
- require 'axlsx/workbook/worksheet/sheet_protection'
34
- require 'axlsx/workbook/worksheet/sheet_pr'
35
- require 'axlsx/workbook/worksheet/dimension'
36
- require 'axlsx/workbook/worksheet/sheet_data'
37
- require 'axlsx/workbook/worksheet/worksheet_drawing'
38
- require 'axlsx/workbook/worksheet/worksheet_comments'
39
- require 'axlsx/workbook/worksheet/worksheet_hyperlink'
40
- require 'axlsx/workbook/worksheet/worksheet_hyperlinks'
41
- require 'axlsx/workbook/worksheet/break'
42
- require 'axlsx/workbook/worksheet/row_breaks'
43
- require 'axlsx/workbook/worksheet/col_breaks'
44
- require 'axlsx/workbook/workbook_view'
45
- require 'axlsx/workbook/workbook_views'
46
- require 'axlsx/workbook/worksheet/worksheet'
47
- require 'axlsx/workbook/shared_strings_table'
48
- require 'axlsx/workbook/defined_name'
49
- require 'axlsx/workbook/defined_names'
50
- require 'axlsx/workbook/worksheet/table_style_info'
51
- require 'axlsx/workbook/worksheet/table'
52
- require 'axlsx/workbook/worksheet/tables'
53
- require 'axlsx/workbook/worksheet/pivot_table_cache_definition'
54
- require 'axlsx/workbook/worksheet/pivot_table'
55
- require 'axlsx/workbook/worksheet/pivot_tables'
56
- require 'axlsx/workbook/worksheet/data_validation'
57
- require 'axlsx/workbook/worksheet/data_validations'
58
- require 'axlsx/workbook/worksheet/sheet_view'
59
- require 'axlsx/workbook/worksheet/sheet_format_pr'
60
- require 'axlsx/workbook/worksheet/pane'
61
- require 'axlsx/workbook/worksheet/selection'
4
+ require_relative 'worksheet/sheet_calc_pr'
5
+ require_relative 'worksheet/auto_filter/auto_filter'
6
+ require_relative 'worksheet/date_time_converter'
7
+ require_relative 'worksheet/protected_range'
8
+ require_relative 'worksheet/protected_ranges'
9
+ require_relative 'worksheet/rich_text_run'
10
+ require_relative 'worksheet/rich_text'
11
+ require_relative 'worksheet/cell_serializer'
12
+ require_relative 'worksheet/cell'
13
+ require_relative 'worksheet/page_margins'
14
+ require_relative 'worksheet/page_set_up_pr'
15
+ require_relative 'worksheet/outline_pr'
16
+ require_relative 'worksheet/page_setup'
17
+ require_relative 'worksheet/header_footer'
18
+ require_relative 'worksheet/print_options'
19
+ require_relative 'worksheet/cfvo'
20
+ require_relative 'worksheet/cfvos'
21
+ require_relative 'worksheet/color_scale'
22
+ require_relative 'worksheet/data_bar'
23
+ require_relative 'worksheet/icon_set'
24
+ require_relative 'worksheet/conditional_formatting'
25
+ require_relative 'worksheet/conditional_formatting_rule'
26
+ require_relative 'worksheet/conditional_formattings'
27
+ require_relative 'worksheet/row'
28
+ require_relative 'worksheet/col'
29
+ require_relative 'worksheet/cols'
30
+ require_relative 'worksheet/comments'
31
+ require_relative 'worksheet/comment'
32
+ require_relative 'worksheet/merged_cells'
33
+ require_relative 'worksheet/sheet_protection'
34
+ require_relative 'worksheet/sheet_pr'
35
+ require_relative 'worksheet/dimension'
36
+ require_relative 'worksheet/sheet_data'
37
+ require_relative 'worksheet/worksheet_drawing'
38
+ require_relative 'worksheet/worksheet_comments'
39
+ require_relative 'worksheet/worksheet_hyperlink'
40
+ require_relative 'worksheet/worksheet_hyperlinks'
41
+ require_relative 'worksheet/break'
42
+ require_relative 'worksheet/row_breaks'
43
+ require_relative 'worksheet/col_breaks'
44
+ require_relative 'workbook_view'
45
+ require_relative 'workbook_views'
46
+ require_relative 'worksheet/worksheet'
47
+ require_relative 'shared_strings_table'
48
+ require_relative 'defined_name'
49
+ require_relative 'defined_names'
50
+ require_relative 'worksheet/table_style_info'
51
+ require_relative 'worksheet/table'
52
+ require_relative 'worksheet/tables'
53
+ require_relative 'worksheet/pivot_table_cache_definition'
54
+ require_relative 'worksheet/pivot_table'
55
+ require_relative 'worksheet/pivot_tables'
56
+ require_relative 'worksheet/data_validation'
57
+ require_relative 'worksheet/data_validations'
58
+ require_relative 'worksheet/sheet_view'
59
+ require_relative 'worksheet/sheet_format_pr'
60
+ require_relative 'worksheet/pane'
61
+ require_relative 'worksheet/selection'
62
62
 
63
63
  # The Workbook class is an xlsx workbook that manages worksheets, charts, drawings and styles.
64
- # The following parts of the Office Open XML spreadsheet specification are not implimented in this version.
64
+ # The following parts of the Office Open XML spreadsheet specification are not implemented in this version.
65
65
  #
66
66
  # bookViews
67
67
  # calcPr
@@ -217,7 +217,7 @@ module Axlsx
217
217
  # Indicates if the epoc date for serialization should be 1904. If false, 1900 is used.
218
218
  @@date1904 = false
219
219
 
220
- # A quick helper to retrive a worksheet by name
220
+ # A quick helper to retrieve a worksheet by name
221
221
  # @param [String] name The name of the sheet you are looking for
222
222
  # @return [Worksheet] The sheet found, or nil
223
223
  def sheet_by_name(name)
@@ -386,7 +386,7 @@ module Axlsx
386
386
  end
387
387
 
388
388
  # The xml:space attribute for the worksheet.
389
- # This determines how whitespace is handled withing the document.
389
+ # This determines how whitespace is handled within the document.
390
390
  # The most relevant part being whitespace in the cell text.
391
391
  # allowed values are :preserve and :default. Axlsx uses :preserve unless
392
392
  # you explicily set this to :default.
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'axlsx/workbook/worksheet/auto_filter/filter_column'
4
- require 'axlsx/workbook/worksheet/auto_filter/filters'
5
- require 'axlsx/workbook/worksheet/auto_filter/sort_state'
3
+ require_relative 'filter_column'
4
+ require_relative 'filters'
5
+ require_relative 'sort_state'
6
6
 
7
7
  module Axlsx
8
8
  # This class represents an auto filter range in a worksheet
@@ -80,7 +80,7 @@ module Axlsx
80
80
  condition.order == :asc ? index1 <=> index2 : index2 <=> index1
81
81
  end
82
82
 
83
- break unless comparison.zero?
83
+ break unless comparison == 0
84
84
  end
85
85
 
86
86
  comparison
@@ -10,7 +10,7 @@ module Axlsx
10
10
  include Axlsx::SerializedAttributes
11
11
 
12
12
  # Creates a new FilterColumn object
13
- # @note This class yeilds its filter object as that is where the vast majority of processing will be done
13
+ # @note This class yields its filter object as that is where the vast majority of processing will be done
14
14
  # @param [Integer|Cell] col_id The zero based index for the column to which this filter will be applied
15
15
  # @param [Symbol] filter_type The symbolized class name of the filter to apply to this column.
16
16
  # @param [Hash] options options for this object and the filter
@@ -13,7 +13,7 @@ module Axlsx
13
13
  # @option [Boolean] blank @see blank
14
14
  # @option [String] calendar_type @see calendar_type
15
15
  # @option [Array] filter_items An array of values that will be used to create filter objects.
16
- # @option [Array] date_group_items An array of hases defining date group item filters to apply.
16
+ # @option [Array] date_group_items An array of hashes defining date group item filters to apply.
17
17
  # @note The recommended way to interact with filter objects is via AutoFilter#add_column
18
18
  # @example
19
19
  # ws.auto_filter.add_column(0, :filters, :blank => true, :calendar_type => 'japan', :filter_items => [100, 'a'])
@@ -36,12 +36,12 @@ module Axlsx
36
36
  # even when those dates are not using the same calendar system / date formatting.
37
37
  attr_reader :calendar_type
38
38
 
39
- # Tells us if the row of the cell provided should be filterd as it
39
+ # Tells us if the row of the cell provided should be filtered as it
40
40
  # does not meet any of the specified filter_items or
41
41
  # date_group_items restrictions.
42
42
  # @param [Cell] cell The cell to test against items
43
43
  # TODO implement this for date filters as well!
44
- def apply(cell)
44
+ def apply(cell) # rubocop:disable Naming/PredicateMethod
45
45
  return false unless cell
46
46
 
47
47
  filter_items.each do |filter|
@@ -138,7 +138,7 @@ module Axlsx
138
138
 
139
139
  # Creates a new DateGroupItem
140
140
  # @param [Hash] options A hash of options to use when
141
- # instanciating the object
141
+ # instantiating the object
142
142
  # @option [String] date_time_grouping the part of the date this
143
143
  # filter should apply for grouping
144
144
  # @option [Integer|String] year @see year
@@ -6,7 +6,7 @@ module Axlsx
6
6
  # Creates a new SortCondition object
7
7
  # @param [Integer] column_index Zero-based index indicating the AutoFilter column to which the sorting should be applied to
8
8
  # @param [Symbol] order The order the column should be sorted on, can only be :asc or :desc
9
- # @param [Array] custom_list An array containg a custom sorting list in order.
9
+ # @param [Array] custom_list An array containing a custom sorting list in order.
10
10
  def initialize(column_index:, order:, custom_list:)
11
11
  Axlsx.validate_int column_index
12
12
  @column_index = column_index
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'axlsx/workbook/worksheet/auto_filter/sort_condition'
3
+ require_relative 'sort_condition'
4
4
 
5
5
  module Axlsx
6
6
  # This class performs sorting on a range in a worksheet
@@ -21,7 +21,7 @@ module Axlsx
21
21
  # It requires a column_index for the sorting, descending and the custom order are optional.
22
22
  # @param [Integer] column_index Zero-based index indicating the AutoFilter column to which the sorting should be applied to
23
23
  # @param [Symbol] order The order the column should be sorted on, can only be :asc or :desc
24
- # @param [Array] custom_list An array containg a custom sorting list in order.
24
+ # @param [Array] custom_list An array containing a custom sorting list in order.
25
25
  # @return [SortCondition]
26
26
  def add_sort_condition(column_index:, order: :asc, custom_list: [])
27
27
  sort_conditions << SortCondition.new(column_index: column_index, order: order, custom_list: custom_list)
@@ -63,19 +63,19 @@ module Axlsx
63
63
  end
64
64
 
65
65
  def first_row
66
- @first_row ||= first_cell.scan(/\d+/).first
66
+ @first_row ||= first_cell[/\d+/]
67
67
  end
68
68
 
69
69
  def first_col
70
- @first_col ||= first_cell.scan(/\D+/).first
70
+ @first_col ||= first_cell[/\D+/]
71
71
  end
72
72
 
73
73
  def last_row
74
- @last_row ||= last_cell.scan(/\d+/).first
74
+ @last_row ||= last_cell[/\d+/]
75
75
  end
76
76
 
77
77
  def last_col
78
- @last_col ||= last_cell.scan(/\D+/).first
78
+ @last_col ||= last_cell[/\D+/]
79
79
  end
80
80
  end
81
81
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Axlsx
4
4
  # A cell in a worksheet.
5
- # Cell stores inforamation requried to serialize a single worksheet cell to xml. You must provde the Row that the cell belongs to and the cells value. The data type will automatically be determed if you do not specify the :type option. The default style will be applied if you do not supply the :style option. Changing the cell's type will recast the value to the type specified. Altering the cell's value via the property accessor will also automatically cast the provided value to the cell's type.
5
+ # Cell stores information required to serialize a single worksheet cell to xml. You must provide the Row that the cell belongs to and the cells value. The data type will automatically be determed if you do not specify the :type option. The default style will be applied if you do not supply the :style option. Changing the cell's type will recast the value to the type specified. Altering the cell's value via the property accessor will also automatically cast the provided value to the cell's type.
6
6
  # @note The recommended way to generate cells is via Worksheet#add_row
7
7
  #
8
8
  # @see Worksheet#add_row
@@ -41,7 +41,7 @@ module Axlsx
41
41
  self.type = type unless type == :string
42
42
 
43
43
  val = options.delete(:style)
44
- self.style = val unless val.nil? || val.zero?
44
+ self.style = val unless val.nil? || val == 0
45
45
  val = options.delete(:formula_value)
46
46
  self.formula_value = val unless val.nil?
47
47
  val = options.delete(:escape_formulas)
@@ -57,11 +57,11 @@ module Axlsx
57
57
  # you need to set this.
58
58
  attr_accessor :formula_value
59
59
 
60
- # An array of available inline styes.
60
+ # An array of available inline styles.
61
61
  # TODO change this to a hash where each key defines attr name and validator (and any info the validator requires)
62
- # then move it out to a module so we can re-use in in other classes.
62
+ # then move it out to a module so we can reuse in in other classes.
63
63
  # needs to define bla=(v) and bla methods on the class that hook into a
64
- # set_attr method that kicks the suplied validator and updates the instance_variable
64
+ # set_attr method that kicks the supplied validator and updates the instance_variable
65
65
  # for the key
66
66
  INLINE_STYLES = [:value, :type, :font_name, :charset,
67
67
  :family, :b, :i, :strike, :outline,
@@ -166,7 +166,7 @@ module Axlsx
166
166
 
167
167
  # Indicates that the cell has one or more of the custom cell styles applied.
168
168
  # @return [Boolean]
169
- def is_text_run? # rubocop:disable Naming/PredicateName
169
+ def is_text_run? # rubocop:disable Naming/PredicatePrefix
170
170
  defined?(@is_text_run) && @is_text_run && !contains_rich_text?
171
171
  end
172
172
 
@@ -410,13 +410,13 @@ module Axlsx
410
410
  CellSerializer.to_xml_string r_index, c_index, self, str
411
411
  end
412
412
 
413
- def is_formula? # rubocop:disable Naming/PredicateName
413
+ def is_formula? # rubocop:disable Naming/PredicatePrefix
414
414
  return false if escape_formulas
415
415
 
416
416
  type == :string && @value.to_s.start_with?(FORMULA_PREFIX)
417
417
  end
418
418
 
419
- def is_array_formula? # rubocop:disable Naming/PredicateName
419
+ def is_array_formula? # rubocop:disable Naming/PredicatePrefix
420
420
  return false if escape_formulas
421
421
 
422
422
  type == :string &&
@@ -549,14 +549,14 @@ module Axlsx
549
549
 
550
550
  case type
551
551
  when :date
552
- self.style = STYLE_DATE if style.zero?
552
+ self.style = STYLE_DATE if style == 0
553
553
  if !v.is_a?(Date) && v.respond_to?(:to_date)
554
554
  v.to_date
555
555
  else
556
556
  v
557
557
  end
558
558
  when :time
559
- self.style = STYLE_DATE if style.zero?
559
+ self.style = STYLE_DATE if style == 0
560
560
  if !v.is_a?(Time) && v.respond_to?(:to_time)
561
561
  v.to_time
562
562
  else
@@ -7,7 +7,7 @@ module Axlsx
7
7
  # Calls the proper serialization method based on type.
8
8
  # @param [Integer] row_index The index of the cell's row
9
9
  # @param [Integer] column_index The index of the cell's column
10
- # @param [String] str The string to apend serialization to.
10
+ # @param [String] str The string to append serialization to.
11
11
  # @return [String]
12
12
  def to_xml_string(row_index, column_index, cell, str = +'')
13
13
  str << '<c r="'
@@ -9,6 +9,7 @@ module Axlsx
9
9
 
10
10
  include Axlsx::OptionsParser
11
11
  include Axlsx::SerializedAttributes
12
+
12
13
  # Create a new Col objects
13
14
  # @param min First column affected by this 'column info' record.
14
15
  # @param max Last column affected by this 'column info' record.
@@ -110,7 +111,7 @@ module Axlsx
110
111
  def width=(v)
111
112
  # Removing this validation make a 10% difference in performance
112
113
  # as it is called EVERY TIME A CELL IS ADDED - the proper solution
113
- # is to only set this if a calculated value is greated than the
114
+ # is to only set this if a calculated value is greater than the
114
115
  # current @width value.
115
116
  # TODO!!!
116
117
  # Axlsx.validate_unsigned_numeric(v) unless v == nil
@@ -121,17 +122,30 @@ module Axlsx
121
122
  # updates the width for this col based on the cells autowidth and
122
123
  # an optionally specified fixed width
123
124
  # @param [Cell] cell The cell to use in updating this col's width
124
- # @param [Integer] fixed_width If this is specified the width is set
125
- # to this value and the cell's attributes are ignored.
125
+ # @param [Numeric, :auto, :ignore, nil] fixed_width Decides how the width
126
+ # of the cell should be updated. If this is specified as as Numeric the
127
+ # width is set to this value and the cell's attributes are ignored. If set
128
+ # to `nil` or `:auto` and `use_autowidth` is true, it uses the autowidth of
129
+ # the cell. If set to `:ignore`, the cell's width is not changed. In any
130
+ # case the col's width is set to the new value only if the current width is
131
+ # smaller than the new one, so that the largest width of all cells in this
132
+ # column is used.
126
133
  # @param [Boolean] use_autowidth If this is false, the cell's
127
134
  # autowidth value will be ignored.
128
135
  def update_width(cell, fixed_width = nil, use_autowidth = true)
129
- if fixed_width.is_a? Numeric
130
- self.width = fixed_width
131
- elsif use_autowidth
132
- cell_width = cell.autowidth
133
- self.width = cell_width unless (width || 0) > (cell_width || 0)
134
- end
136
+ cell_width =
137
+ case fixed_width
138
+ when Numeric
139
+ fixed_width
140
+ when nil, :auto
141
+ cell.autowidth if use_autowidth
142
+ when :ignore
143
+ nil
144
+ else
145
+ raise ArgumentError, "fixed_with must be a Numeric, :auto, :ignore or nil, but is '#{fixed_width.inspect}'"
146
+ end
147
+
148
+ self.width = cell_width unless (width || 0) > (cell_width || 0)
135
149
  end
136
150
 
137
151
  # Serialize this columns data to an xml string
@@ -11,8 +11,8 @@ module Axlsx
11
11
  # @param [Hash] options
12
12
  # @option [String] author the author of the comment
13
13
  # @option [String] text The text for the comment
14
- # @option [String] ref The refence (e.g. 'A3' where this comment will be anchored.
15
- # @option [Boolean] visible This controls the visiblity of the associated vml_shape.
14
+ # @option [String] ref The reference (e.g. 'A3' where this comment will be anchored.
15
+ # @option [Boolean] visible This controls the visibility of the associated vml_shape.
16
16
  def initialize(comments, options = {})
17
17
  raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments)
18
18
 
@@ -37,7 +37,7 @@ module Axlsx
37
37
  # @note the author, text and ref options are required
38
38
  # @option options [String] author The name of the author for this comment
39
39
  # @option options [String] text The text for this comment
40
- # @option options [Stirng|Cell] ref The cell that this comment is attached to.
40
+ # @option options [String|Cell] ref The cell that this comment is attached to.
41
41
  def add_comment(options = {})
42
42
  raise ArgumentError, "Comment require an author" unless options[:author]
43
43
  raise ArgumentError, "Comment requires text" unless options[:text]
@@ -83,7 +83,7 @@ module Axlsx
83
83
  def to_xml_string(str = +'')
84
84
  str << '<conditionalFormatting sqref="' << sqref << '">'
85
85
  rules.each_with_index do |rule, index|
86
- str << ' ' unless index.zero?
86
+ str << ' ' unless index == 0
87
87
  rule.to_xml_string(str)
88
88
  end
89
89
  str << '</conditionalFormatting>'
@@ -24,7 +24,7 @@ module Axlsx
24
24
  # @option options [Integer] rank If a top/bottom N rule, the value of N
25
25
  # @option options [Integer] stdDev The number of standard deviations above or below the average to match
26
26
  # @option options [Boolean] stopIfTrue Stop evaluating rules after this rule matches
27
- # @option options [Symbol] timePeriod The time period in a date occuring... rule
27
+ # @option options [Symbol] timePeriod The time period in a date occurring... rule
28
28
  # @option options [String] formula The formula to match against in i.e. an equal rule. Use a [minimum, maximum] array for cellIs between/notBetween conditionals.
29
29
  def initialize(options = {})
30
30
  @color_scale = @data_bar = @icon_set = @formula = nil