Class: Sinatra::Chiro::Parameters::DateTimeValidator

Inherits:
Base
  • Object
show all
Defined in:
lib/sinatra/chiro/parameters/datetime.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#default, #description, #initialize, #name, #name_display, #optional, #type, #type_description

Constructor Details

This class inherits a constructor from Sinatra::Chiro::Parameters::Base

Instance Method Details

#commentObject



14
15
16
# File 'lib/sinatra/chiro/parameters/datetime.rb', line 14

def comment
  'Must be expressed according to ISO 8601 (ie. YYYY-MM-DDThh:mm:ss)'
end

#validate(given) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/sinatra/chiro/parameters/datetime.rb', line 5

def validate(given)
  DateTime.parse(given.to_s)

  if given[name] !~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/
    "#{name_display} parameter must be a string in the format: yyyy-mm-ddThh:mm:ss"
  end
rescue ArgumentError
  "#{name_display} parameter invalid"
end