From e8d7480a633eb6b5b1a8de01d010382cce86fb48 Mon Sep 17 00:00:00 2001 From: Andy Meneely Date: Tue, 13 Oct 2015 15:01:14 -0400 Subject: [PATCH] Range option shouldn't fail on [] Fixes #107 --- CHANGELOG.md | 3 +++ lib/squib/args/card_range.rb | 2 +- spec/args/range_spec.rb | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a695126..06d61e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ Features Compatibility change: * Stripping leading and trailing whitespace of xlsx and csv values by default might change how your data gets parsed. +Bugs fixes: +* The `range` option everywhere doesn't fail on `[]` (#107) + ## v0.7.0 / 2015-09-11 Features diff --git a/lib/squib/args/card_range.rb b/lib/squib/args/card_range.rb index c3352ff..2ac668f 100644 --- a/lib/squib/args/card_range.rb +++ b/lib/squib/args/card_range.rb @@ -23,7 +23,7 @@ module Squib input = 0..(deck_size - 1) if input == :all input = (input.to_i)..(input.to_i) if input.respond_to? :to_i raise ArgumentError.new("#{input} must be Enumerable (i.e. respond_to :each).") unless input.respond_to? :each - raise ArgumentError.new("#{input} is outside of deck range of 0..#{deck_size-1}") if input.max > (deck_size - 1) + raise ArgumentError.new("#{input} is outside of deck range of 0..#{deck_size-1}") if (!input.max.nil?) && (input.max > (deck_size - 1)) input end diff --git a/spec/args/range_spec.rb b/spec/args/range_spec.rb index dcfe879..08e413d 100644 --- a/spec/args/range_spec.rb +++ b/spec/args/range_spec.rb @@ -33,4 +33,9 @@ describe Squib::Args::CardRange do expect(range.to_a).to eq([0]) end + it 'allows [] as an empty range' do + range = Squib::Args::CardRange.new([], deck_size: 5) + expect(range.to_a).to eq([]) + end + end \ No newline at end of file