Class: JsonTableSchema::Types::Time
- Inherits:
-
Base
- Object
- Base
- JsonTableSchema::Types::Time
show all
- Defined in:
- lib/jsontableschema/types/time.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#cast, #initialize, #set_format, #test
Methods included from Helpers
#convert_to_boolean, #false_values, #get_class_for_type, #true_values, #type_class_lookup
Class Method Details
.supported_constraints ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/jsontableschema/types/time.rb', line 9
def self.supported_constraints
[
'required',
'pattern',
'enum',
'minimum',
'maximum',
]
end
|
Instance Method Details
#cast_any(value) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/jsontableschema/types/time.rb', line 32
def cast_any(value)
return value if value.is_a?(type)
begin
return ::Tod::TimeOfDay.parse(value)
rescue ArgumentError
raise JsonTableSchema::InvalidTimeType.new("#{value} is not a valid time")
end
end
|
#cast_default(value) ⇒ Object
27
28
29
30
|
# File 'lib/jsontableschema/types/time.rb', line 27
def cast_default(value)
@format_string = iso8601
cast_fmt(value)
end
|
#cast_fmt(value) ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/jsontableschema/types/time.rb', line 42
def cast_fmt(value)
return value if value.is_a?(type)
begin
time = ::Time.strptime(value, @format_string)
return time.to_time_of_day
rescue ArgumentError, TypeError
raise JsonTableSchema::InvalidTimeType.new("#{value} is not a valid time")
end
end
|
23
24
25
|
# File 'lib/jsontableschema/types/time.rb', line 23
def iso8601
'%H:%M:%S'
end
|
5
6
7
|
# File 'lib/jsontableschema/types/time.rb', line 5
def name
'time'
end
|
19
20
21
|
# File 'lib/jsontableschema/types/time.rb', line 19
def type
::Tod::TimeOfDay
end
|