Module: InputValidator
- Included in:
- DataValidators::ApelDataValidator, DataValidators::LogstashDataValidator, DataValidators::PbsDataValidator, OneDataAccessor, RedisConf
- Defined in:
- lib/input_validator.rb
Overview
Simple helper module for input validation
Constant Summary collapse
- URI_RE =
/\A#{URI.regexp}\z/
- NUMBER_RE =
/\A[[:digit:]]+\z/
- DECIMAL_RE =
/\A[[:digit:]]+\.[[:digit:]]+\z/
- STRING_RE =
/\A[[:print:]]+\z/
- NON_ZERO_NUMBER_RE =
/\A[1-9][[:digit:]]*\z/
Instance Method Summary collapse
- #decimal?(object) ⇒ Boolean
- #is?(object, regexp) ⇒ Boolean
- #non_zero_number?(object) ⇒ Boolean
- #number?(object) ⇒ Boolean
- #string?(object) ⇒ Boolean
- #uri?(object) ⇒ Boolean
Instance Method Details
#decimal?(object) ⇒ Boolean
19 20 21 |
# File 'lib/input_validator.rb', line 19 def decimal?(object) is?(object, DECIMAL_RE) || number?(object) end |
#is?(object, regexp) ⇒ Boolean
11 12 13 |
# File 'lib/input_validator.rb', line 11 def is?(object, regexp) object.to_s =~ regexp end |
#non_zero_number?(object) ⇒ Boolean
31 32 33 |
# File 'lib/input_validator.rb', line 31 def non_zero_number?(object) is?(object, NON_ZERO_NUMBER_RE) end |
#number?(object) ⇒ Boolean
15 16 17 |
# File 'lib/input_validator.rb', line 15 def number?(object) is?(object, NUMBER_RE) end |
#string?(object) ⇒ Boolean
27 28 29 |
# File 'lib/input_validator.rb', line 27 def string?(object) is?(object, STRING_RE) end |
#uri?(object) ⇒ Boolean
23 24 25 |
# File 'lib/input_validator.rb', line 23 def uri?(object) is?(object, URI_RE) end |