class TableSchema::Types::Base
Public Class Methods
new(field)
click to toggle source
# File lib/tableschema/types/base.rb, line 8 def initialize(field) @field = field set_format end
Public Instance Methods
cast(value)
click to toggle source
# File lib/tableschema/types/base.rb, line 13 def cast(value) send("cast_#{@format}", value) rescue NoMethodError => e if e.message.start_with?('undefined method `cast_') raise(TableSchema::InvalidFormat.new("The format `#{@format}` is not supported by the type `#{@type}`")) else raise e end end
test(value)
click to toggle source
# File lib/tableschema/types/base.rb, line 23 def test(value) cast(value) true rescue TableSchema::Exception false end
Private Instance Methods
set_format()
click to toggle source
# File lib/tableschema/types/base.rb, line 32 def set_format if (@field[:format] || '').start_with?('fmt:') @format, @format_string = *@field[:format].split(':', 2) else @format = @field[:format] || TableSchema::DEFAULTS[:format] end end