class TableSchema::Types::String
Public Class Methods
supported_constraints()
click to toggle source
# File lib/tableschema/types/string.rb, line 9 def self.supported_constraints [ 'required', 'unique', 'pattern', 'enum', 'minLength', 'maxLength', ] end
Public Instance Methods
cast_binary(value)
click to toggle source
# File lib/tableschema/types/string.rb, line 63 def cast_binary(value) value = cast_default(value) Base64.strict_decode64(value) rescue ArgumentError raise TableSchema::InvalidBinary.new("#{value} is not a valid binary string") end
cast_default(value)
click to toggle source
# File lib/tableschema/types/string.rb, line 28 def cast_default(value) if value.is_a?(type) return value else raise TableSchema::InvalidCast.new("#{value} is not a #{name}") end end
cast_email(value)
click to toggle source
# File lib/tableschema/types/string.rb, line 36 def cast_email(value) value = cast_default(value) if (value =~ email_pattern) != nil value else raise TableSchema::InvalidEmail.new("#{value} is not a valid email") end end
cast_uri(value)
click to toggle source
# File lib/tableschema/types/string.rb, line 45 def cast_uri(value) value = cast_default(value) if (value =~ URI::regexp) != nil value else raise TableSchema::InvalidURI.new("#{value} is not a valid uri") end end
cast_uuid(value)
click to toggle source
# File lib/tableschema/types/string.rb, line 54 def cast_uuid(value) value = cast_default(value) if UUID.validate(value) value else raise TableSchema::InvalidUUID.new("#{value} is not a valid UUID") end end
email_pattern()
click to toggle source
# File lib/tableschema/types/string.rb, line 24 def email_pattern /[^@]+@[^@]+\.[^@]+/ end
name()
click to toggle source
# File lib/tableschema/types/string.rb, line 5 def name 'string' end
type()
click to toggle source
# File lib/tableschema/types/string.rb, line 20 def type ::String end