Sha256: 031f0ec92f847ae508a8af2743c60d9dd03e59a33323ab25c7512cb655148b8e

Contents?: true

Size: 528 Bytes

Versions: 8

Compression:

Stored size: 528 Bytes

Contents

module CLIUtils
  # A Validator to verify whether a Pref answer
  # is a valid time.
  class TimeValidator < PrefValidator
    # Runs the Validator against the answer.
    # @param [Object] text The "text" to evaluate
    # @return [String]
    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 })$/
      @message = "Response is not a time: #{ text }"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cliutils-2.2.6 lib/cliutils/prefs/pref_validators/time_validator.rb
cliutils-2.2.5 lib/cliutils/prefs/pref_validators/time_validator.rb
cliutils-2.2.4 lib/cliutils/prefs/pref_validators/time_validator.rb
cliutils-2.2.3 lib/cliutils/prefs/pref_validators/time_validator.rb
cliutils-2.2.2 lib/cliutils/prefs/pref_validators/time_validator.rb
cliutils-2.2.1 lib/cliutils/prefs/pref_validators/time_validator.rb
cliutils-2.2.0 lib/cliutils/prefs/pref_validators/time_validator.rb
cliutils-2.1.4 lib/cliutils/prefs/pref_validators/time_validator.rb