summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLee Jarvis <ljjarvis@gmail.com>2015-05-18 08:46:44 +0100
committerLee Jarvis <ljjarvis@gmail.com>2015-05-18 08:46:44 +0100
commit078039fc8eb0419c0a049efec05a6964baa3f35f (patch)
tree3bfe8e7cef6c792ebfc0e977b8af34c1ef18b4e8
parent4078a1bcfa731fe0f15e3e7d2d4bcf0ac312d435 (diff)
parente7521a65b01560ac997ccb907d33e4b3795533a7 (diff)
downloadslop-078039fc8eb0419c0a049efec05a6964baa3f35f.tar.gz
Merge pull request #167 from spk/regexp-support-4.1
Added support for Regexp
-rw-r--r--lib/slop/types.rb7
-rw-r--r--test/types_test.rb13
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/slop/types.rb b/lib/slop/types.rb
index df67aee..ad7461c 100644
--- a/lib/slop/types.rb
+++ b/lib/slop/types.rb
@@ -61,6 +61,13 @@ module Slop
end
end
+ # Cast the option argument to a Regexp.
+ class RegexpOption < Option
+ def call(value)
+ Regexp.new(value)
+ end
+ end
+
# An option that discards the return value, inherits from Bool
# since it does not expect an argument.
class NullOption < BoolOption
diff --git a/test/types_test.rb b/test/types_test.rb
index 39cccc9..81ae3ba 100644
--- a/test/types_test.rb
+++ b/test/types_test.rb
@@ -100,3 +100,16 @@ describe Slop::NullOption do
assert_equal({}, @result.to_hash)
end
end
+
+describe Slop::RegexpOption do
+ before do
+ @options = Slop::Options.new
+ @exclude = @options.regexp "--exclude"
+ @exclude_value = "redirect|news"
+ @result = @options.parse %W(--exclude #{@exclude_value})
+ end
+
+ it "returns the value as a Regexp" do
+ assert_equal Regexp.new(@exclude_value), @result[:exclude]
+ end
+end