valigator-csv 1.0.0 → 1.0.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/valigator/csv/validator.rb +16 -3
- data/lib/valigator/csv/version.rb +1 -1
- data/valigator-csv.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1efa995498cf14a8bf892006e140abb02e3aee2e
|
4
|
+
data.tar.gz: 5b26ffad290e8334a508381d8709c15d07c31f19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec34eacd57451041c1e2121387becb196fd3e0f3201008ecfaec658801de839c1f0678a770d27a3aa3984a88485a0b4d7831caa1f4200894c6a39c2493c805b4
|
7
|
+
data.tar.gz: 83a1ce0eafcad4816753b4c06929e949e655fd18b3a0f999d4d27f0b5c57a7c097976e28f13f6616a81fbb2493ee583380e02844e012d9c054318e508f50e6f8
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'csvlint'
|
2
2
|
require 'active_support/core_ext/string/filters'
|
3
|
-
require 'active_support/hash_with_indifferent_access'
|
4
3
|
|
5
4
|
module Valigator
|
6
5
|
module CSV
|
@@ -27,7 +26,7 @@ module Valigator
|
|
27
26
|
|
28
27
|
def check_with_csvlint(options = {})
|
29
28
|
File.open(filename, "r:#{options[:encoding] || 'UTF-8'}") do |file|
|
30
|
-
validator = ::Csvlint::Validator.new(file,
|
29
|
+
validator = ::Csvlint::Validator.new(file, build_dialect(options), build_schema(options))
|
31
30
|
|
32
31
|
validator.errors.each { |error| add_to_errors error }
|
33
32
|
validator.warnings.each { |warning| add_to_errors warning }
|
@@ -36,6 +35,14 @@ module Valigator
|
|
36
35
|
|
37
36
|
|
38
37
|
|
38
|
+
def build_dialect(options = {})
|
39
|
+
return {} unless options[:dialect]
|
40
|
+
|
41
|
+
stringify_keys options[:dialect]
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
39
46
|
def build_schema(options = {})
|
40
47
|
return unless options[:headers]
|
41
48
|
|
@@ -46,7 +53,7 @@ module Valigator
|
|
46
53
|
|
47
54
|
def build_header_fields(options = {})
|
48
55
|
options[:headers].map do |header|
|
49
|
-
header_definition =
|
56
|
+
header_definition = stringify_keys(header)
|
50
57
|
|
51
58
|
::Csvlint::Field.new(header_definition["name"], header_definition["constraints"])
|
52
59
|
end
|
@@ -54,6 +61,12 @@ module Valigator
|
|
54
61
|
|
55
62
|
|
56
63
|
|
64
|
+
def stringify_keys(hash)
|
65
|
+
JSON.parse JSON.dump(hash)
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
|
57
70
|
def add_to_errors(original_error)
|
58
71
|
return if original_error.type == :encoding
|
59
72
|
|
data/valigator-csv.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.
|
21
|
+
spec.add_runtime_dependency "csvlint"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.10"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valigator-csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Nagy
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-11-
|
12
|
+
date: 2015-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: csvlint
|