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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8993e666de0387ddc501a2011674df88b2f468e9
4
- data.tar.gz: 389552b0605f1e134a95da8ac765d5d79028d744
3
+ metadata.gz: cb93fabf19ab19297d56db70ee012f199feadfa3
4
+ data.tar.gz: 8499c95e4cf186bc4ecf5858bebf5d8464d86863
5
5
  SHA512:
6
- metadata.gz: 161a6ec1e68b6ba53dfa85a4229584e0a1384f05e02bb6ed6e168320ebc8a9541fe4f44c7a569a741e576f8d5f8ab90393f90addfc9b9e443717855e2b22452a
7
- data.tar.gz: 8b197a067d941359a31f30b763a959c8f2f519f68e935894cdf7901b992a5f276e54caf6fcbe7ec28a29ec4dc9a4cd2eb59ece79923d7bc29c4da2a391856ffc
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.parse(record)
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('date', OpencJsonSchemaFormats::DateFormatValidator)
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)
@@ -1,3 +1,3 @@
1
1
  module OpencJsonSchemaFormats
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openc_json_schema_formats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seb Bacon