Class: TableSchema::Types::Duration

Inherits:
Base
  • Object
show all
Defined in:
lib/tableschema/types/duration.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#cast, #initialize, #test

Methods included from Helpers

#deep_symbolize_keys, #get_class_for_type, #read_file, #type_class_lookup

Constructor Details

This class inherits a constructor from TableSchema::Types::Base

Class Method Details

.supported_constraintsObject



9
10
11
12
13
14
15
16
17
# File 'lib/tableschema/types/duration.rb', line 9

def self.supported_constraints
  [
    'required',
    'unique',
    'enum',
    'minimum',
    'maximum',
  ]
end

Instance Method Details

#cast_default(value) ⇒ Object



23
24
25
26
27
# File 'lib/tableschema/types/duration.rb', line 23

def cast_default(value)
  ActiveSupport::Duration.parse(value)
rescue ActiveSupport::Duration::ISO8601Parser::ParsingError, TypeError
    raise TableSchema::InvalidDurationType.new("#{value} is not a valid duration")
end

#nameObject



5
6
7
# File 'lib/tableschema/types/duration.rb', line 5

def name
  'duration'
end

#typeObject



19
20
21
# File 'lib/tableschema/types/duration.rb', line 19

def type
  ActiveSupport::Duration
end