Skip to content

Commit bc5375d

Browse files
afdev82andreavocado
andcommitted
fallback to 0.0 in case of no gutter, fixes #1343
Prefer fetch for default value Co-authored-by: André Jährling <85166619+andreavocado@users.noreply.github.com>
1 parent ce37403 commit bc5375d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/prawn/grid.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ def subdivide(total, num, gutter)
145145

146146
def apply_gutter(options)
147147
if options.key?(:gutter)
148-
@gutter = Float(options[:gutter])
148+
@gutter = Float(options.fetch(:gutter, 0.0))
149149
@row_gutter = @gutter
150150
@column_gutter = @gutter
151151
else
152-
@row_gutter = Float(options[:row_gutter])
153-
@column_gutter = Float(options[:column_gutter])
152+
@row_gutter = Float(options.fetch(:row_gutter, 0.0))
153+
@column_gutter = Float(options.fetch(:column_gutter, 0.0))
154154
@gutter = 0
155155
end
156156
end

spec/prawn/document_grid_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
expect(pdf.grid.gutter).to eq(0.1)
1414
end
1515

16+
it 'allows definition of a grid without gutter' do
17+
pdf.define_grid(columns: 3, rows: 5)
18+
expect(pdf.grid.columns).to eq(3)
19+
expect(pdf.grid.rows).to eq(5)
20+
expect(pdf.grid.gutter).to eq(0.0)
21+
end
22+
1623
it 'allows re-definition of a grid' do
1724
pdf.define_grid(columns: 5, rows: 8, gutter: 0.1)
1825
expect(pdf.grid.columns).to eq(5)

0 commit comments

Comments
 (0)