Class: JsonTableSchema::Field

Inherits:
Hash
  • Object
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_classObject (readonly)

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

#constraintsObject



24
25
26
# File 'lib/jsontableschema/field.rb', line 24

def constraints
  self['constraints'] || {}
end

#formatObject



20
21
22
# File 'lib/jsontableschema/field.rb', line 20

def format
  self['format'] || 'default'
end

#nameObject



12
13
14
# File 'lib/jsontableschema/field.rb', line 12

def name
  self['name']
end

#typeObject



16
17
18
# File 'lib/jsontableschema/field.rb', line 16

def type
  self['type'] || 'string'
end