Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use worksheet without block #45

Merged
merged 8 commits into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/xlsxtream/workbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def build_worksheet(name = nil, options = {})

@io.add_file "xl/worksheets/sheet#{sheet_id}.xml"

worksheet = Worksheet.new(@io, sheet_id, name, :sst => sst, :auto_format => auto_format, :columns => columns)
worksheet = Worksheet.new(@io, :id => sheet_id, :name => name, :sst => sst, :auto_format => auto_format, :columns => columns)
@worksheets << worksheet

worksheet
Expand Down
14 changes: 9 additions & 5 deletions lib/xlsxtream/worksheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

module Xlsxtream
class Worksheet
attr_reader :id, :name

def initialize(io, id, name, options = {})
def initialize(io, options = {})
felixbuenemann marked this conversation as resolved.
Show resolved Hide resolved
@io = io
@id = id
@name = name
@rownum = 1
@closed = false
@options = options
Expand All @@ -32,6 +28,14 @@ def closed?
@closed
end

def id
@options[:id]
end

def name
@options[:name]
end

private

def write_header
Expand Down
16 changes: 8 additions & 8 deletions test/xlsxtream/worksheet_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Xlsxtream
class WorksheetTest < Minitest::Test
def test_empty_worksheet
io = StringIO.new
ws = Worksheet.new(io, 1, 'test')
ws = Worksheet.new(io)
ws.close
expected = \
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'"\r\n" \
Expand All @@ -17,7 +17,7 @@ def test_empty_worksheet

def test_add_row
io = StringIO.new
ws = Worksheet.new(io, 1, 'test')
ws = Worksheet.new(io)
ws << ['foo']
ws.add_row ['bar']
ws.close
Expand All @@ -33,7 +33,7 @@ def test_add_row
def test_add_row_with_sst_option
io = StringIO.new
mock_sst = { 'foo' => 0 }
ws = Worksheet.new(io, 1, 'test', :sst => mock_sst)
ws = Worksheet.new(io, :sst => mock_sst)
ws << ['foo']
ws.close
expected = \
Expand All @@ -46,7 +46,7 @@ def test_add_row_with_sst_option

def test_add_row_with_auto_format_option
io = StringIO.new
ws = Worksheet.new(io, 1, 'test', :auto_format => true)
ws = Worksheet.new(io, :auto_format => true)
ws << ['1.5']
ws.close
expected = \
Expand All @@ -59,7 +59,7 @@ def test_add_row_with_auto_format_option

def test_add_columns_via_worksheet_options
io = StringIO.new
ws = Worksheet.new(io, 1, 'test', { :columns => [ {}, {}, { :width_pixels => 42 } ] } )
ws = Worksheet.new(io, { :columns => [ {}, {}, { :width_pixels => 42 } ] } )
ws.close
expected = \
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'"\r\n" \
Expand All @@ -74,7 +74,7 @@ def test_add_columns_via_worksheet_options

def test_add_columns_via_worksheet_options_and_add_rows
io = StringIO.new
ws = Worksheet.new(io, 1, 'test', { :columns => [ {}, {}, { :width_pixels => 42 } ] } )
ws = Worksheet.new(io, { :columns => [ {}, {}, { :width_pixels => 42 } ] } )
ws << ['foo']
ws.add_row ['bar']
ws.close
Expand All @@ -93,12 +93,12 @@ def test_add_columns_via_worksheet_options_and_add_rows
end

def test_respond_to_id
ws = Worksheet.new(StringIO.new, 1, 'test')
ws = Worksheet.new(StringIO.new, id: 1)
assert_equal 1, ws.id
end

def test_respond_to_name
ws = Worksheet.new(StringIO.new, 1, 'test')
ws = Worksheet.new(StringIO.new, name: 'test')
assert_equal 'test', ws.name
end
end
Expand Down