Class: CLIUtils::TimeValidator
- Inherits:
-
PrefValidator
- Object
- PrefValidator
- CLIUtils::TimeValidator
- Defined in:
- lib/cliutils/prefs/pref_validators/time_validator.rb
Overview
A Validator to verify whether a Pref answer is a valid time.
Instance Attribute Summary
Attributes inherited from PrefValidator
Instance Method Summary collapse
-
#validate(text) ⇒ String
Runs the Validator against the answer.
Methods included from Messaging
Instance Method Details
#validate(text) ⇒ String
Runs the Validator against the answer.
8 9 10 11 12 13 |
# File 'lib/cliutils/prefs/pref_validators/time_validator.rb', line 8 def validate(text) military_regex = '([01]?[0-9]|2[0-3])\:[0-5][0-9]' regular_regex = "#{ military_regex }(\\s?[AaPp][Mm])?" @is_valid = text.to_s =~ /^(#{ military_regex }|#{ regular_regex })$/ = "Response is not a time: #{ text }" end |