Class: JsonTableSchema::Types::String
- Inherits:
-
Base
- Object
- Base
- JsonTableSchema::Types::String
show all
- Defined in:
- lib/jsontableschema/types/string.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#cast, #initialize, #set_format, #test
Methods included from Helpers
#convert_to_boolean, #false_values, #get_class_for_type, #true_values, #type_class_lookup
Class Method Details
.supported_constraints ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/jsontableschema/types/string.rb', line 9
def self.supported_constraints
[
'required',
'pattern',
'enum',
'minLength',
'maxLength',
]
end
|
Instance Method Details
#cast_default(value) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/jsontableschema/types/string.rb', line 27
def cast_default(value)
if value.is_a?(type)
return value
else
raise JsonTableSchema::InvalidCast.new("#{value} is not a #{name}")
end
end
|
#cast_email(value) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/jsontableschema/types/string.rb', line 35
def cast_email(value)
value = cast_default(value)
if (value =~ email_pattern) != nil
value
else
raise JsonTableSchema::InvalidEmail.new("#{value} is not a valid email")
end
end
|
#cast_uri(value) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/jsontableschema/types/string.rb', line 44
def cast_uri(value)
value = cast_default(value)
if (value =~ URI::regexp) != nil
value
else
raise JsonTableSchema::InvalidURI.new("#{value} is not a valid uri")
end
end
|
#cast_uuid(value) ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/jsontableschema/types/string.rb', line 53
def cast_uuid(value)
value = cast_default(value)
if UUID.validate(value)
value
else
raise JsonTableSchema::InvalidUUID.new("#{value} is not a valid UUID")
end
end
|
#email_pattern ⇒ Object
23
24
25
|
# File 'lib/jsontableschema/types/string.rb', line 23
def email_pattern
/[^@]+@[^@]+\.[^@]+/
end
|
5
6
7
|
# File 'lib/jsontableschema/types/string.rb', line 5
def name
'string'
end
|
19
20
21
|
# File 'lib/jsontableschema/types/string.rb', line 19
def type
::String
end
|