openc_json_schema_formats 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/openc_json_schema_formats.rb +29 -2
- data/lib/openc_json_schema_formats/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb93fabf19ab19297d56db70ee012f199feadfa3
|
4
|
+
data.tar.gz: 8499c95e4cf186bc4ecf5858bebf5d8464d86863
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49dfed2e61af8624e9a5e700cd01047313542ce702c2b9df33655dab314c52781f902f0e24369f7b8069af867062d95bb45ef0d982fd25ebcbd1a7c961d0598a
|
7
|
+
data.tar.gz: 7683621f2c131403f4e45500ab5f90c44207d827813b327b70db2db443d4ecb6d199c891f6193c2e2ad66dd0273b7a43275f11d4bf1512ded9801f85d1858581
|
@@ -1,15 +1,42 @@
|
|
1
1
|
require "openc_json_schema_formats/version"
|
2
2
|
require "json_validation"
|
3
|
+
require "uri"
|
3
4
|
|
4
5
|
module OpencJsonSchemaFormats
|
5
6
|
class DateFormatValidator
|
6
7
|
def validate(record)
|
7
|
-
Date.
|
8
|
+
Date.strptime(record, '%Y-%m-%d')
|
8
9
|
true
|
9
10
|
rescue ArgumentError
|
10
11
|
false
|
11
12
|
end
|
12
13
|
end
|
14
|
+
|
15
|
+
class NonBlankValidator
|
16
|
+
def validate(record)
|
17
|
+
!(record.is_a?(String) && record.strip == '')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class URIValidator
|
22
|
+
# Actually, this only checks http and https formats, so isn't
|
23
|
+
# really for URIs
|
24
|
+
def validate(record)
|
25
|
+
begin
|
26
|
+
uri = URI.parse(record)
|
27
|
+
uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
|
28
|
+
rescue URI::InvalidURIError
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
13
33
|
end
|
14
34
|
|
15
|
-
JsonValidation.add_format_validator(
|
35
|
+
JsonValidation.add_format_validator(
|
36
|
+
'date', OpencJsonSchemaFormats::DateFormatValidator)
|
37
|
+
|
38
|
+
JsonValidation.add_format_validator(
|
39
|
+
'non-blank', OpencJsonSchemaFormats::NonBlankValidator)
|
40
|
+
|
41
|
+
JsonValidation.add_format_validator(
|
42
|
+
'uri', OpencJsonSchemaFormats::URIValidator)
|