Class: ForemanGutterball::Apipie::Validators::DateValidator
- Inherits:
-
Apipie::Validator::BaseValidator
- Object
- Apipie::Validator::BaseValidator
- ForemanGutterball::Apipie::Validators::DateValidator
- Defined in:
- lib/foreman_gutterball/apipie/validators.rb
Class Method Summary collapse
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(param_description, argument) ⇒ DateValidator
constructor
A new instance of DateValidator.
- #validate(value) ⇒ Object
Constructor Details
#initialize(param_description, argument) ⇒ DateValidator
Returns a new instance of DateValidator.
5 6 7 8 |
# File 'lib/foreman_gutterball/apipie/validators.rb', line 5 def initialize(param_description, argument) super(param_description) @type = argument end |
Class Method Details
.build(param_description, argument, _options, _block) ⇒ Object
21 22 23 24 25 |
# File 'lib/foreman_gutterball/apipie/validators.rb', line 21 def self.build(param_description, argument, , _block) if argument == Date new(param_description, argument) end end |
Instance Method Details
#description ⇒ Object
27 28 29 |
# File 'lib/foreman_gutterball/apipie/validators.rb', line 27 def description "Must be a #{@type} in the form of YYYY-MM-DD." end |
#validate(value) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/foreman_gutterball/apipie/validators.rb', line 10 def validate(value) return false if value.nil? return false unless value =~ /\A\d{4}(-\d{1,2}){2}\z/ begin Date.parse(value) # make sure this is a valid date and not 2015-02-45, etc. rescue return false end true end |