Class: TableSchema::Types::Boolean

Inherits:
Base
  • Object
show all
Defined in:
lib/tableschema/types/boolean.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



15
16
17
18
19
20
21
# File 'lib/tableschema/types/boolean.rb', line 15

def self.supported_constraints
  [
    'required',
    'pattern',
    'enum',
  ]
end

Instance Method Details

#cast_default(value) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tableschema/types/boolean.rb', line 27

def cast_default(value)
  true_values = @field.fetch(:trueValues, TableSchema::DEFAULTS[:true_values])
  false_values = @field.fetch(:falseValues, TableSchema::DEFAULTS[:false_values])
  if [true, false].include?(value)
    return value
  elsif true_values.include?(value)
    return true
  elsif false_values.include?(value)
    return false
  else
    raise TableSchema::InvalidCast.new("#{value} is not a #{name}")
  end
end

#nameObject



11
12
13
# File 'lib/tableschema/types/boolean.rb', line 11

def name
  'boolean'
end

#typeObject



23
24
25
# File 'lib/tableschema/types/boolean.rb', line 23

def type
  ::Boolean
end