Skip to content

Commit

Permalink
fix : avoid warning variable not initialized.
Browse files Browse the repository at this point in the history
  • Loading branch information
cxn03651 committed Dec 30, 2023
1 parent 6f00031 commit 2016f09
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 129 deletions.
1 change: 1 addition & 0 deletions lib/writeexcel/cell_range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class CellRange

def initialize(worksheet)
@worksheet = worksheet
@row_min = @row_max = @col_min = @col_max = nil
end

def increment_row_max
Expand Down
1 change: 1 addition & 0 deletions lib/writeexcel/comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Worksheet < BIFFWriter
class Collection
def initialize
@items = {}
@array = nil
end

def <<(item)
Expand Down
1 change: 1 addition & 0 deletions lib/writeexcel/workbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def initialize(file, default_formats = {})
@localtime = Time.now

@defined_names = []
@fileclosed = nil

setup_built_in_formats(default_formats)

Expand Down
63 changes: 36 additions & 27 deletions lib/writeexcel/worksheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def initialize(workbook, name, name_utf16be) # :nodoc:
@title_range = TitleRange.new(self)
@print_range = PrintRange.new(self)

@print_headers = 0
@print_gridlines = 1
@screen_gridlines = 1

Expand Down Expand Up @@ -155,6 +156,18 @@ def initialize(workbook, name, name_utf16be) # :nodoc:

@table = []
@row_data = {}
@header = ''
@header_encoding = nil
@footer = ''
@footer_encoding = nil
@hidden = nil
@selected = nil
@protect = nil
@hcenter = nil
@vcenter = nil
@display_arabic = nil
@frozen = nil
@hide_zeros = nil
end

#
Expand Down Expand Up @@ -353,8 +366,8 @@ def activate
# worksheet2.activate
# worksheet1.hide
#
def hide
@hidden = true
def hide(hidden = :hidden)
@hidden = hidden

# A hidden worksheet shouldn't be active or selected.
@selected = false
Expand Down Expand Up @@ -673,7 +686,7 @@ def set_row(row, height = nil, format = nil, hidden = false, level = 0, collapse
#
def set_column(*args)
# Check for a cell reference in A1 notation and substitute row and column
if args[0].respond_to?(:=~) && args[0] =~ /^\D/
if args[0].respond_to?(:match) && args[0] =~ /^\D/
array = substitute_cellref(*args)
firstcol = array[1]
lastcol = array[3]
Expand Down Expand Up @@ -963,11 +976,11 @@ def merge_range(*args)
format = args[5]
encoding = args[6] ? 1 : 0

merge_range_core(rwFirst, colFirst, rwLast, colLast, string, format, encoding) do |rwFirst, colFirst, string, format, encoding|
if encoding != 0
write_utf16be_string(rwFirst, colFirst, string, format)
merge_range_core(rwFirst, colFirst, rwLast, colLast, string, format, encoding) do |_rwFirst, _colFirst, _string, _format, _encoding|
if _encoding != 0
write_utf16be_string(_rwFirst, _colFirst, _string, _format)
else
write(rwFirst, colFirst, string, format)
write(_rwFirst, _colFirst, _string, _format)
end
end
end
Expand All @@ -994,8 +1007,8 @@ def merge_range_with_date_time(*args)
format = args[5]
encoding = nil

merge_range_core(rwFirst, colFirst, rwLast, colLast, string, format, encoding) do |rwFirst, colFirst, string, format, encoding|
write_date_time(rwFirst, colFirst, string, format)
merge_range_core(rwFirst, colFirst, rwLast, colLast, string, format, encoding) do |_rwFirst, _colFirst, _string, _format, _encoding|
write_date_time(_rwFirst, _colFirst, _string, _format)
end
end

Expand Down Expand Up @@ -2227,24 +2240,24 @@ def write(*args)
match = eval("#{sub} self, args")
return match if match
end
end if token.respond_to?(:=~)
end if token.respond_to?(:match)

# Match an array ref.
if token.respond_to?(:to_ary)
write_row(*args)
elsif token.respond_to?(:coerce) # Numeric
write_number(*args)
# Match http, https or ftp URL
elsif token.respond_to?(:=~) && token =~ %r|^[fh]tt?ps?://|
elsif token.respond_to?(:match) && token =~ %r|^[fh]tt?ps?://|
write_url(*args)
# Match mailto:
elsif token.respond_to?(:=~) && token =~ %r|^mailto:|
elsif token.respond_to?(:match) && token =~ %r|^mailto:|
write_url(*args)
# Match internal or external sheet link
elsif token.respond_to?(:=~) && token =~ %r!^(?:in|ex)ternal:!
elsif token.respond_to?(:match) && token =~ %r!^(?:in|ex)ternal:!
write_url(*args)
# Match formula
elsif token.respond_to?(:=~) && token =~ /^=/
elsif token.respond_to?(:match) && token =~ /^=/
write_formula(*args)
# Match blank
elsif token == ''
Expand Down Expand Up @@ -4313,7 +4326,7 @@ def selected=(val) # :nodoc:
end

def hidden? # :nodoc:
@hidden
@hidden == :hidden
end

def hidden=(val) # :nodoc:
Expand Down Expand Up @@ -4941,31 +4954,27 @@ def xf_record_index(row, col, xf=nil) #:nodoc:
def substitute_cellref(cell, *args) #:nodoc:
return [cell, *args] if cell.respond_to?(:coerce) # Numeric

cell.upcase!
normalized_cell = cell.upcase

case normalized_cell
# Convert a column range: 'A:A' or 'B:G'.
# A range such as A:A is equivalent to A1:65536, so add rows as required
if cell =~ /\$?([A-I]?[A-Z]):\$?([A-I]?[A-Z])/
when /\$?([A-I]?[A-Z]):\$?([A-I]?[A-Z])/
row1, col1 = cell_to_rowcol($1 + '1')
row2, col2 = cell_to_rowcol($2 + '65536')
return [row1, col1, row2, col2, *args]
end

# Convert a cell range: 'A1:B7'
if cell =~ /\$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)/
when /\$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)/
row1, col1 = cell_to_rowcol($1)
row2, col2 = cell_to_rowcol($2)
return [row1, col1, row2, col2, *args]
end

# Convert a cell reference: 'A1' or 'AD2000'
if (cell =~ /\$?([A-I]?[A-Z]\$?\d+)/)
when /\$?([A-I]?[A-Z]\$?\d+)/
row1, col1 = cell_to_rowcol($1)
return [row1, col1, *args]

else
raise("Unknown cell reference #{normalized_cell}")
end

raise("Unknown cell reference #{cell}")
end

#
Expand Down Expand Up @@ -6958,7 +6967,7 @@ def row_col_notation(args) # :nodoc:
# ruby 3.2 no longer handles =~ for various types
return args unless args[0].respond_to?(:=~)

if args[0] =~ /^\D/
if args[0].respond_to?(:match) && args[0] =~ /^\D/
substitute_cellref(*args)
else
args
Expand Down
1 change: 1 addition & 0 deletions lib/writeexcel/worksheets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Worksheets < Array

def initialize
@activesheet = nil
@firstsheet = nil
end

def activesheet_index
Expand Down
8 changes: 4 additions & 4 deletions test/test_04_dimensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def setup
end

def teardown
if @workbook.instance_variable_get(:@filehandle)
@workbook.instance_variable_get(:@filehandle).close(true)
if @workbook.instance_variable_get("@filehandle")
@workbook.instance_variable_get("@filehandle").close(true)
end
if @worksheet.instance_variable_get(:@filehandle)
@worksheet.instance_variable_get(:@filehandle).close(true)
if @worksheet.instance_variable_get("@filehandle")
@worksheet.instance_variable_get("@filehandle").close(true)
end
end

Expand Down
29 changes: 13 additions & 16 deletions test/test_05_rows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,22 @@ def setup
end

def teardown
if @workbook.instance_variable_get(:@filehandle)
@workbook.instance_variable_get(:@filehandle).close(true)
end
if @worksheet.instance_variable_get(:@filehandle)
@worksheet.instance_variable_get(:@filehandle).close(true)
if @workbook.instance_variable_get("@filehandle")
@workbook.instance_variable_get("@filehandle").close(true)
end
end

def test_1
file = StringIO.new
workbook = WriteExcel.new(file)
workbook.compatibility_mode(1)
@workbook = WriteExcel.new(file)
@workbook.compatibility_mode(1)
@tests = []

# for test case 1
row = 1
col1 = 0
col2 = 0
worksheet = workbook.add_worksheet
worksheet = @workbook.add_worksheet
worksheet.set_row(row, 15)
@tests.push(
[
Expand All @@ -54,7 +51,7 @@ def test_1
row = 2
col1 = 0
col2 = 0
worksheet = workbook.add_worksheet
worksheet = @workbook.add_worksheet
worksheet.write(row, col1, 'Test')
worksheet.write(row, col2, 'Test')
@tests.push(
Expand All @@ -72,7 +69,7 @@ def test_1
row = 3
col1 = 0
col2 = 1
worksheet = workbook.add_worksheet
worksheet = @workbook.add_worksheet
worksheet.write(row, col1, 'Test')
worksheet.write(row, col2, 'Test')
@tests.push(
Expand All @@ -89,7 +86,7 @@ def test_1
row = 4
col1 = 1
col2 = 1
worksheet = workbook.add_worksheet
worksheet = @workbook.add_worksheet
worksheet.write(row, col1, 'Test')
worksheet.write(row, col2, 'Test')
@tests.push(
Expand All @@ -106,7 +103,7 @@ def test_1
row = 5
col1 = 1
col2 = 255
worksheet = workbook.add_worksheet
worksheet = @workbook.add_worksheet
worksheet.write(row, col1, 'Test')
worksheet.write(row, col2, 'Test')
@tests.push(
Expand All @@ -123,7 +120,7 @@ def test_1
row = 6
col1 = 255
col2 = 255
worksheet = workbook.add_worksheet
worksheet = @workbook.add_worksheet
worksheet.write(row, col1, 'Test')
worksheet.write(row, col2, 'Test')
@tests.push(
Expand All @@ -140,7 +137,7 @@ def test_1
row = 7
col1 = 2
col2 = 9
worksheet = workbook.add_worksheet
worksheet = @workbook.add_worksheet
worksheet.set_row(row, 15)
worksheet.write(row, col1, 'Test')
worksheet.write(row, col2, 'Test')
Expand All @@ -154,8 +151,8 @@ def test_1
]
)

workbook.biff_only = 1
workbook.close
@workbook.biff_only = 1
@workbook.close
# Read in the row records
rows = []

Expand Down
17 changes: 7 additions & 10 deletions test/test_06_extsst.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,24 @@ def setup
end

def teardown
if @workbook.instance_variable_get(:@filehandle)
@workbook.instance_variable_get(:@filehandle).close(true)
end
if @worksheet.instance_variable_get(:@filehandle)
@worksheet.instance_variable_get(:@filehandle).close(true)
if @workbook.instance_variable_get("@filehandle")
@workbook.instance_variable_get("@filehandle").close(true)
end
end

def test_to_tests
@tests.each do |test|
io = StringIO.new
workbook = WriteExcel.new(io)
workbook.not_using_tmpfile
@workbook = WriteExcel.new(io)
@workbook.not_using_tmpfile

str_unique = test[0]

workbook.__send__("calculate_extsst_size", str_unique)
@workbook.__send__("calculate_extsst_size", str_unique)

assert_equal(test[1], workbook.extsst_buckets,
assert_equal(test[1], @workbook.extsst_buckets,
" \tBucket number for #{str_unique} strings")
assert_equal(test[2], workbook.extsst_bucket_size,
assert_equal(test[2], @workbook.extsst_bucket_size,
" \tBucket size for #{str_unique} strings")
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/test_21_escher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def setup
end

def teardown
if @workbook.instance_variable_get(:@filehandle)
@workbook.instance_variable_get(:@filehandle).close(true)
if @workbook.instance_variable_get("@filehandle")
@workbook.instance_variable_get("@filehandle").close(true)
end
if @worksheet.instance_variable_get(:@filehandle)
@worksheet.instance_variable_get(:@filehandle).close(true)
if @worksheet.instance_variable_get("@filehandle")
@worksheet.instance_variable_get("@filehandle").close(true)
end
end

Expand Down
7 changes: 2 additions & 5 deletions test/test_22_mso_drawing_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ def setup
end

def teardown
if @workbook.instance_variable_get(:@filehandle)
@workbook.instance_variable_get(:@filehandle).close(true)
end
if @worksheet.instance_variable_get(:@filehandle)
@worksheet.instance_variable_get(:@filehandle).close(true)
if @workbook.instance_variable_get("@filehandle")
@workbook.instance_variable_get("@filehandle").close(true)
end
end

Expand Down
8 changes: 4 additions & 4 deletions test/test_23_note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def setup
end

def teardown
if @workbook.instance_variable_get(:@filehandle)
@workbook.instance_variable_get(:@filehandle).close(true)
if @workbook.instance_variable_get("@filehandle")
@workbook.instance_variable_get("@filehandle").close(true)
end
if @worksheet.instance_variable_get(:@filehandle)
@worksheet.instance_variable_get(:@filehandle).close(true)
if @worksheet.instance_variable_get("@filehandle")
@worksheet.instance_variable_get("@filehandle").close(true)
end
end

Expand Down
Loading

0 comments on commit 2016f09

Please sign in to comment.