Class: Sinatra::Chiro::Parameters::TimeValidator

Inherits:
Base
  • Object
show all
Defined in:
lib/sinatra/chiro/parameters/time.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



15
16
17
# File 'lib/sinatra/chiro/parameters/time.rb', line 15

def comment
  'Must be expressed according to ISO 8601 (ie. hh:mm:ss)'
end

#validate(given) ⇒ Object



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

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

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