From bc5375de9e0fb09d549d1528fb49db491a8e1812 Mon Sep 17 00:00:00 2001 From: Antonio Facciolo Date: Tue, 19 Mar 2024 09:31:04 +0100 Subject: [PATCH] fallback to 0.0 in case of no gutter, fixes #1343 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prefer fetch for default value Co-authored-by: André Jährling <85166619+andreavocado@users.noreply.github.com> --- lib/prawn/grid.rb | 6 +++--- spec/prawn/document_grid_spec.rb | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/prawn/grid.rb b/lib/prawn/grid.rb index 80cd9e268..4912edadc 100644 --- a/lib/prawn/grid.rb +++ b/lib/prawn/grid.rb @@ -145,12 +145,12 @@ def subdivide(total, num, gutter) def apply_gutter(options) if options.key?(:gutter) - @gutter = Float(options[:gutter]) + @gutter = Float(options.fetch(:gutter, 0.0)) @row_gutter = @gutter @column_gutter = @gutter else - @row_gutter = Float(options[:row_gutter]) - @column_gutter = Float(options[:column_gutter]) + @row_gutter = Float(options.fetch(:row_gutter, 0.0)) + @column_gutter = Float(options.fetch(:column_gutter, 0.0)) @gutter = 0 end end diff --git a/spec/prawn/document_grid_spec.rb b/spec/prawn/document_grid_spec.rb index 94f77ad67..4c79e1d6b 100644 --- a/spec/prawn/document_grid_spec.rb +++ b/spec/prawn/document_grid_spec.rb @@ -13,6 +13,13 @@ expect(pdf.grid.gutter).to eq(0.1) end + it 'allows definition of a grid without gutter' do + pdf.define_grid(columns: 3, rows: 5) + expect(pdf.grid.columns).to eq(3) + expect(pdf.grid.rows).to eq(5) + expect(pdf.grid.gutter).to eq(0.0) + end + it 'allows re-definition of a grid' do pdf.define_grid(columns: 5, rows: 8, gutter: 0.1) expect(pdf.grid.columns).to eq(5)