When auto-width is enabled, having an empty column (e.g. a column width only nil or '' values) causes NoMethodError: undefined method '+' for nil:NilClass because the corresponding value in @column_widths ends up as nil. This PR adds a test-case that fails on that condition, and also fixes the problem that causes the error. The fix works by replacing nil or 0 with the default column width like is also done here. To be able to test it and to allow and consuming code to access the final column width, I decided to use transform_values! so the final changes are reflected in @column_widths and as such in sheet.calculated_column_widths, even though the workbook is already closed.
I considered a fix here by replacing > with >= to allow the resulting value to become 0, however this would not work because of the + 0.2. That + 0.2 is also not reflected in the final @column_widths, however that was already not the case with the way the test(s) work, so I figured this would be the most intuitive way to fix the implementation while still allowing a simple test.
When auto-width is enabled, having an empty column (e.g. a column width only
nil
or''
values) causesNoMethodError: undefined method '+' for nil:NilClass
because the corresponding value in@column_widths
ends up asnil
. This PR adds a test-case that fails on that condition, and also fixes the problem that causes the error. The fix works by replacingnil
or0
with the default column width like is also done here. To be able to test it and to allow and consuming code to access the final column width, I decided to usetransform_values!
so the final changes are reflected in@column_widths
and as such insheet.calculated_column_widths
, even though the workbook is already closed.I considered a fix here by replacing
>
with>=
to allow the resulting value to become0
, however this would not work because of the+ 0.2
. That+ 0.2
is also not reflected in the final@column_widths
, however that was already not the case with the way the test(s) work, so I figured this would be the most intuitive way to fix the implementation while still allowing a simple test.