summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/cell.rb
diff options
context:
space:
mode:
authorPaul Kmiec <[email protected]>2023-05-12 11:08:06 -0700
committerPaul Kmiec <[email protected]>2023-05-15 16:58:24 -0700
commitd18d7f9696211a0ed899153ce4d8ae9cb9c15b6d (patch)
tree7462e8f8655fa9da7df4d36c9fb2d189cbf3fcae /lib/axlsx/workbook/worksheet/cell.rb
parent1413f9be2cef8e0cc77113b94d1d0e4a7afc8ed6 (diff)
downloadcaxlsx-d18d7f9696211a0ed899153ce4d8ae9cb9c15b6d.tar.gz
caxlsx-d18d7f9696211a0ed899153ce4d8ae9cb9c15b6d.zip
Fix safe rubocop offenses in Axslx::Cell
There are 2 offenses left but they would be breaking backwards compatibility.
Diffstat (limited to 'lib/axlsx/workbook/worksheet/cell.rb')
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index 74ca7360..37b8e205 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -42,7 +42,7 @@ module Axlsx
self.type = type unless type == :string
val = options.delete(:style)
- self.style = val unless val.nil? || val == 0
+ self.style = val unless val.nil? || val.zero?
val = options.delete(:formula_value)
self.formula_value = val unless val.nil?
val = options.delete(:escape_formulas)
@@ -291,7 +291,7 @@ module Axlsx
# @see u
def u=(v)
- v = :single if (v == true || v == 1 || v == :true || v == 'true')
+ v = :single if [true, 1, :true, 'true'].include?(v)
set_run_style :validate_cell_u, :u, v
end
@@ -354,7 +354,7 @@ module Axlsx
# @example Absolute Cell Reference
# ws.rows.first.cells.first.r #=> "$A$1"
def r_abs
- "$#{r.match(%r{([A-Z]+)([0-9]+)})[1, 2].join('$')}"
+ "$#{r.match(/([A-Z]+)([0-9]+)/)[1, 2].join('$')}"
end
# @return [Integer] The cellXfs item index applied to this cell.
@@ -379,7 +379,7 @@ module Axlsx
start, stop = if target.is_a?(String)
[self.r, target]
elsif target.is_a?(Cell)
- Axlsx.sort_cells([self, target]).map { |c| c.r }
+ Axlsx.sort_cells([self, target]).map(&:r)
end
self.row.worksheet.merge_cells "#{start}:#{stop}" unless stop.nil?
end
@@ -509,13 +509,11 @@ module Axlsx
:time
elsif v.is_a?(TrueClass) || v.is_a?(FalseClass)
:boolean
- elsif v.to_s =~ Axlsx::NUMERIC_REGEX && v.respond_to?(:to_i)
+ elsif v.respond_to?(:to_i) && v.to_s =~ Axlsx::NUMERIC_REGEX
:integer
- elsif v.to_s =~ Axlsx::SAFE_FLOAT_REGEX && v.respond_to?(:to_f)
+ elsif v.respond_to?(:to_f) && (v.to_s =~ Axlsx::SAFE_FLOAT_REGEX || ((matchdata = v.to_s.match(MAYBE_FLOAT_REGEX)) && (Float::MIN_10_EXP..Float::MAX_10_EXP).cover?(matchdata[:exp].to_i)))
:float
- elsif (matchdata = v.to_s.match(MAYBE_FLOAT_REGEX)) && (Float::MIN_10_EXP..Float::MAX_10_EXP).cover?(matchdata[:exp].to_i) && v.respond_to?(:to_f)
- :float
- elsif v.to_s =~ Axlsx::ISO_8601_REGEX
+ elsif Axlsx::ISO_8601_REGEX.match?(v.to_s)
:iso_8601
elsif v.is_a? RichText
:richtext
@@ -533,14 +531,14 @@ module Axlsx
case type
when :date
- self.style = STYLE_DATE if self.style == 0
+ self.style = STYLE_DATE if self.style.zero?
if !v.is_a?(Date) && v.respond_to?(:to_date)
v.to_date
else
v
end
when :time
- self.style = STYLE_DATE if self.style == 0
+ self.style = STYLE_DATE if self.style.zero?
if !v.is_a?(Time) && v.respond_to?(:to_time)
v.to_time
else