Class: JsonTableSchema::Field
- Inherits:
-
Hash
- Object
- Hash
- JsonTableSchema::Field
show all
- Includes:
- Helpers
- Defined in:
- lib/jsontableschema/field.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helpers
#convert_to_boolean, #false_values, #get_class_for_type, #true_values, #type_class_lookup
Constructor Details
#initialize(descriptor) ⇒ Field
Returns a new instance of Field.
7
8
9
10
|
# File 'lib/jsontableschema/field.rb', line 7
def initialize(descriptor)
self.merge! descriptor
@type_class = get_type
end
|
Instance Attribute Details
#type_class ⇒ Object
Returns the value of attribute type_class.
5
6
7
|
# File 'lib/jsontableschema/field.rb', line 5
def type_class
@type_class
end
|
Instance Method Details
#cast_value(col) ⇒ Object
28
29
30
31
32
|
# File 'lib/jsontableschema/field.rb', line 28
def cast_value(col)
klass = get_class_for_type(type)
converter = Kernel.const_get(klass).new(self)
converter.cast(col)
end
|
#constraints ⇒ Object
24
25
26
|
# File 'lib/jsontableschema/field.rb', line 24
def constraints
self['constraints'] || {}
end
|
20
21
22
|
# File 'lib/jsontableschema/field.rb', line 20
def format
self['format'] || 'default'
end
|
#name ⇒ Object
12
13
14
|
# File 'lib/jsontableschema/field.rb', line 12
def name
self['name']
end
|
#type ⇒ Object
16
17
18
|
# File 'lib/jsontableschema/field.rb', line 16
def type
self['type'] || 'string'
end
|