Class: TableSchema::Types::Integer
- Inherits:
-
Base
- Object
- Base
- TableSchema::Types::Integer
show all
- Defined in:
- lib/tableschema/types/integer.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
Class Method Details
.supported_constraints ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/tableschema/types/integer.rb', line 9
def self.supported_constraints
[
'required',
'unique',
'pattern',
'enum',
'minimum',
'maximum',
]
end
|
Instance Method Details
#cast_default(value) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/tableschema/types/integer.rb', line 24
def cast_default(value)
if value.nil? || value.is_a?(type)
value
else
bare_number = @field.fetch(:bareNumber, TableSchema::DEFAULTS[:bare_number])
if !bare_number
value = value.gsub(/((^\D*)|(\D*$))/, '')
end
Integer(value)
end
rescue ArgumentError
raise TableSchema::InvalidCast.new("#{value} is not a #{name}")
end
|
5
6
7
|
# File 'lib/tableschema/types/integer.rb', line 5
def name
'integer'
end
|
20
21
22
|
# File 'lib/tableschema/types/integer.rb', line 20
def type
::Integer
end
|