summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLee Jarvis <leejarvis@fastmail.com>2020-01-17 08:51:06 +0000
committerGitHub <noreply@github.com>2020-01-17 08:51:06 +0000
commitc3825b39a56c1d64820ae30141c4604c857143b7 (patch)
tree86cb923b01d602ca410fc6dc1734a3aaf29a3dc8 /lib
parent02e3ec521f7a7440ec5d324e81e8ba85a749bcf0 (diff)
parente28fbcf19c9e1b6d8875be680c6bb4f40ab0c21c (diff)
downloadslop-c3825b39a56c1d64820ae30141c4604c857143b7.tar.gz
Merge pull request #250 from flavono123/float-scientific-notation
FloatOption: Add support for scientific notation and + sign
Diffstat (limited to 'lib')
-rw-r--r--lib/slop/types.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/slop/types.rb b/lib/slop/types.rb
index 4cd6136..c53319c 100644
--- a/lib/slop/types.rb
+++ b/lib/slop/types.rb
@@ -51,9 +51,10 @@ module Slop
# Cast the option argument to a Float.
class FloatOption < Option
+ FLOAT_STRING_REGEXP = /\A[+-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?\z/.freeze
+
def call(value)
- # TODO: scientific notation, etc.
- value =~ /\A-?\d*\.*\d+\z/ && value.to_f
+ value =~ FLOAT_STRING_REGEXP && value.to_f
end
end