Skip to content

Commit

Permalink
Fix internal use of deprecated Excelx::Cell.new
Browse files Browse the repository at this point in the history
Calling `Excelx#set` internally called `Excelx::Cell.new`, which is
deprecated in favor of `Excelx::Cell.create_cell`.

I tried using the recommended `Excelx::Cell.create_cell`, however it
expects a `type` as the first argument. `#set` tries to infer the type
via  [`cell_type_by_value`](https://github.com/roo-rb/roo/blob/709464c77623be2bc09b2103405d90ded7604a75/lib/roo/base.rb#L175-L182),
however it only returns `:float` or `:string`, but
`Excelx::Cell.cell_class` doesn't support `:float`.

Even if I add `:float` to map to `Cell::Number`, then there's a dilemma
because `Excelx::Cell.create_cell` passes all the arguments except the
first onto the specific cell class, but the arity of `Cell::String` is 5
whereas the arity of `Cell::Number` is 6, meaning `Excelx#set` would
need to initialize each cell class individually to pass the appropriate
arguments.

Therefore I landed on simply using `Cell::Base`. It's probably not the
most accurate, but given persisting the spreadsheet isn't an option, the
uses for `Excelx#set` should be minimal. In my case, I simply use it in
testing to avoid creating new files for every possible scenario, opting
to manually set various cells to triggered assorted scenarios.

Fixes roo-rb#529.
  • Loading branch information
cgunther committed Sep 22, 2021
1 parent 709464c commit c927ee5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/roo/excelx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def last_column(sheet = nil)
def set(row, col, value, sheet = nil) #:nodoc:
key = normalize(row, col)
cell_type = cell_type_by_value(value)
sheet_for(sheet).cells[key] = Cell.new(value, cell_type, nil, cell_type, value, nil, nil, nil, Coordinate.new(row, col))
sheet_for(sheet).cells[key] = Cell::Base.new(value, nil, nil, nil, nil, Coordinate.new(row, col))
end

# Returns the formula at (row,col).
Expand Down

0 comments on commit c927ee5

Please sign in to comment.