diff --git a/lib/squib/input_helpers.rb b/lib/squib/input_helpers.rb index 298bccc..79798a5 100644 --- a/lib/squib/input_helpers.rb +++ b/lib/squib/input_helpers.rb @@ -200,11 +200,11 @@ module Squib Squib::UNIT_CONVERSION_PARAMS.each_pair do |param_name, api_param| if needed_params.include? param_name opts[api_param].each_with_index do |arg, i| - case arg.to_s + case arg.to_s.rstrip when /in$/ #ends with "in" - opts[api_param][i] = arg[0..-2].to_f * @dpi + opts[api_param][i] = arg.rstrip[0..-2].to_f * @dpi when /cm$/ #ends with "cm" - opts[api_param][i] = arg[0..-2].to_f * @dpi * @@INCHES_IN_CM + opts[api_param][i] = arg.rstrip[0..-2].to_f * @dpi * @@INCHES_IN_CM end end end diff --git a/spec/input_helpers_spec.rb b/spec/input_helpers_spec.rb index 8cf6bad..7202fa7 100644 --- a/spec/input_helpers_spec.rb +++ b/spec/input_helpers_spec.rb @@ -167,6 +167,13 @@ describe Squib::InputHelpers do expect(opts).to eq({:x => [156.0, 600.0]}) #assume 300dpi default end + it 'handles whitespace' do + args = {x: ['1in ']} + needed_params = [:x] + opts = @deck.send(:convert_units, args, needed_params) + expect(opts).to eq({:x => [300.0] }) #assume 300dpi default + end + it 'converts centimeters' do args = {x: ['2cm']} needed_params = [:x] @@ -177,12 +184,12 @@ describe Squib::InputHelpers do end context '#rowify' do - # it 'does nothing on an integer' do - # opts = @deck.send(:rowify, {columns: 2, rows: 2}) - # expect(opts).to eq({ columns: 2, - # rows: 2 - # }) - # end + it 'does nothing on an integer' do + opts = @deck.send(:rowify, {columns: 2, rows: 2}) + expect(opts).to eq({ columns: 2, + rows: 2 + }) + end it 'computes properly on non-integer' do opts = @deck.send(:rowify, {columns: 1, rows: :infinite})