csv2hash 0.6.2 → 0.6.3
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/.gitignore +2 -5
- data/.yardoc/checksums +25 -0
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +15 -1
- data/README.md +32 -4
- data/UPGRADE.md +2 -0
- data/bin/generate_doc +3 -0
- data/config/example.csv +10 -0
- data/config/rules.yml +7 -0
- data/doc/Cell.html +282 -0
- data/doc/Csv2hash/Adapter/Abstract.html +215 -0
- data/doc/Csv2hash/Adapter/Base/UnsupportedAdapter.html +123 -0
- data/doc/Csv2hash/Adapter/Base.html +201 -0
- data/doc/Csv2hash/Adapter/CsvAdapter.html +348 -0
- data/doc/Csv2hash/Adapter/MemoryAdapter.html +348 -0
- data/doc/Csv2hash/Adapter.html +117 -0
- data/doc/Csv2hash/DataWrapper.html +500 -0
- data/doc/Csv2hash/Definition.html +1008 -0
- data/doc/Csv2hash/Discover.html +192 -0
- data/doc/Csv2hash/Expectation.html +202 -0
- data/doc/Csv2hash/ExtraValidator.html +207 -0
- data/doc/Csv2hash/Main.html +1298 -0
- data/doc/Csv2hash/Notifier.html +189 -0
- data/doc/Csv2hash/Parser/Collection.html +283 -0
- data/doc/Csv2hash/Parser/Mapping.html +266 -0
- data/doc/Csv2hash/Parser.html +121 -0
- data/doc/Csv2hash/StructureValidator/Deprecation.html +215 -0
- data/doc/Csv2hash/StructureValidator/MaxColumns.html +327 -0
- data/doc/Csv2hash/StructureValidator/MinColumns.html +327 -0
- data/doc/Csv2hash/StructureValidator/ValidationError.html +123 -0
- data/doc/Csv2hash/StructureValidator/Validator.html +184 -0
- data/doc/Csv2hash/StructureValidator.html +311 -0
- data/doc/Csv2hash/Validator/Collection.html +217 -0
- data/doc/Csv2hash/Validator/Mapping.html +200 -0
- data/doc/Csv2hash/Validator.html +295 -0
- data/doc/Csv2hash.html +131 -0
- data/doc/CsvArray.html +200 -0
- data/doc/Registry.html +312 -0
- data/doc/_index.html +391 -0
- data/doc/class_list.html +54 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +339 -0
- data/doc/file.README.html +499 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +499 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +178 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +473 -0
- data/doc/top-level-namespace.html +114 -0
- data/lib/csv2hash/definition.rb +3 -3
- data/lib/csv2hash/version.rb +1 -1
- data/lib/csv2hash/yaml_loader.rb +33 -0
- data/lib/csv2hash.rb +28 -8
- data/spec/csv2hash/yaml_loader_spec.rb +20 -0
- data/spec/csv2hash_spec.rb +13 -10
- metadata +56 -1
data/lib/csv2hash.rb
CHANGED
@@ -16,6 +16,7 @@ require_relative 'csv2hash/data_wrapper'
|
|
16
16
|
require_relative 'csv2hash/notifier'
|
17
17
|
require_relative 'csv2hash/extra_validator'
|
18
18
|
require_relative 'csv2hash/adapters/base'
|
19
|
+
require_relative 'csv2hash/yaml_loader'
|
19
20
|
|
20
21
|
require 'active_support/core_ext/array/extract_options'
|
21
22
|
|
@@ -36,11 +37,11 @@ module Csv2hash
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def [] definition_name
|
39
|
-
@@registry[definition_name]
|
40
|
+
@@registry[definition_name.to_sym]
|
40
41
|
end
|
41
42
|
|
42
43
|
def []= definition_name, role
|
43
|
-
@@registry[definition_name] = role
|
44
|
+
@@registry[definition_name.to_sym] = role
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
@@ -48,11 +49,13 @@ module Csv2hash
|
|
48
49
|
|
49
50
|
attr_accessor :definition, :file_path_or_data, :data, :notifier, :break_on_failure, :errors, :options
|
50
51
|
|
51
|
-
def initialize
|
52
|
-
self.options
|
53
|
-
self.definition
|
54
|
-
self.
|
55
|
-
self.
|
52
|
+
def initialize definition_file_or_symbol, file_path_or_data, *args
|
53
|
+
self.options = args.extract_options!
|
54
|
+
self.definition = load_definition(definition_file_or_symbol)
|
55
|
+
self.file_path_or_data = file_path_or_data
|
56
|
+
self.break_on_failure = false
|
57
|
+
self.errors = []
|
58
|
+
self.notifier = Notifier.new
|
56
59
|
|
57
60
|
dynamic_lib_loading 'Parser'
|
58
61
|
dynamic_lib_loading 'Validator'
|
@@ -112,7 +115,7 @@ module Csv2hash
|
|
112
115
|
|
113
116
|
def data_source
|
114
117
|
@data_source ||= begin
|
115
|
-
adapter_name = self.file_path_or_data.
|
118
|
+
adapter_name = self.file_path_or_data.respond_to?(:to_path) ? :csv : :memory
|
116
119
|
adapter = Adapter::Base.create(adapter_name, self.file_path_or_data)
|
117
120
|
adapter.source
|
118
121
|
end
|
@@ -129,5 +132,22 @@ module Csv2hash
|
|
129
132
|
self.extend Module.module_eval("Csv2hash::#{type}::Collection")
|
130
133
|
end
|
131
134
|
end
|
135
|
+
|
136
|
+
def load_definition definition_file_or_symbol
|
137
|
+
case definition_file_or_symbol
|
138
|
+
when String
|
139
|
+
config_file = definition_file_or_symbol
|
140
|
+
config_file = Pathname(definition_file_or_symbol) unless config_file.respond_to?(:to_path)
|
141
|
+
loader = YamlLoader.new(config_file).tap &:load!
|
142
|
+
loader.definition
|
143
|
+
when Symbol
|
144
|
+
Main[definition_file_or_symbol]
|
145
|
+
when Definition
|
146
|
+
definition_file_or_symbol
|
147
|
+
else
|
148
|
+
raise 'unsupported definition'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
132
152
|
end
|
133
153
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Csv2hash
|
4
|
+
describe YamlLoader do
|
5
|
+
let(:config_file) { 'config/rules.yml' }
|
6
|
+
|
7
|
+
subject do
|
8
|
+
YamlLoader.new config_file
|
9
|
+
end
|
10
|
+
|
11
|
+
before do
|
12
|
+
subject.load!
|
13
|
+
end
|
14
|
+
|
15
|
+
specify do
|
16
|
+
expect(subject.definition.name).to eql('example')
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/spec/csv2hash_spec.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module Csv2hash
|
4
|
+
describe Main do
|
5
|
+
let(:config_file) { 'config/rules.yml' }
|
6
|
+
let(:loader) { YamlLoader.new(config_file).tap &:load! }
|
7
|
+
let(:data_source) { 'config/example.csv' }
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
subject do
|
10
|
+
Main.new(loader.definition, data_source, ignore_blank_line: false)
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
context '...' do
|
14
|
+
specify do
|
15
|
+
expect(subject.options.fetch(:ignore_blank_line)).to eql(false)
|
16
|
+
end
|
14
17
|
end
|
15
|
-
end
|
16
18
|
|
19
|
+
end
|
17
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv2hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel AZEMAR
|
@@ -83,6 +83,7 @@ dependencies:
|
|
83
83
|
description: DSL to map a CSV to a Ruby Hash
|
84
84
|
email: joel.azemar@gmail.com
|
85
85
|
executables:
|
86
|
+
- generate_doc
|
86
87
|
- launch_irb
|
87
88
|
- load_rvm
|
88
89
|
extensions: []
|
@@ -92,6 +93,10 @@ files:
|
|
92
93
|
- ".gitignore"
|
93
94
|
- ".rspec"
|
94
95
|
- ".travis.yml"
|
96
|
+
- ".yardoc/checksums"
|
97
|
+
- ".yardoc/object_types"
|
98
|
+
- ".yardoc/objects/root.dat"
|
99
|
+
- ".yardoc/proxy_types"
|
95
100
|
- CHANGELOG.md
|
96
101
|
- Gemfile
|
97
102
|
- Gemfile.lock
|
@@ -99,10 +104,56 @@ files:
|
|
99
104
|
- README.md
|
100
105
|
- Rakefile
|
101
106
|
- UPGRADE.md
|
107
|
+
- bin/generate_doc
|
102
108
|
- bin/launch_irb
|
103
109
|
- bin/load_rvm
|
110
|
+
- config/example.csv
|
111
|
+
- config/rules.yml
|
104
112
|
- coverage/.resultset.json.lock
|
105
113
|
- csv2hash.gemspec
|
114
|
+
- doc/Cell.html
|
115
|
+
- doc/Csv2hash.html
|
116
|
+
- doc/Csv2hash/Adapter.html
|
117
|
+
- doc/Csv2hash/Adapter/Abstract.html
|
118
|
+
- doc/Csv2hash/Adapter/Base.html
|
119
|
+
- doc/Csv2hash/Adapter/Base/UnsupportedAdapter.html
|
120
|
+
- doc/Csv2hash/Adapter/CsvAdapter.html
|
121
|
+
- doc/Csv2hash/Adapter/MemoryAdapter.html
|
122
|
+
- doc/Csv2hash/DataWrapper.html
|
123
|
+
- doc/Csv2hash/Definition.html
|
124
|
+
- doc/Csv2hash/Discover.html
|
125
|
+
- doc/Csv2hash/Expectation.html
|
126
|
+
- doc/Csv2hash/ExtraValidator.html
|
127
|
+
- doc/Csv2hash/Main.html
|
128
|
+
- doc/Csv2hash/Notifier.html
|
129
|
+
- doc/Csv2hash/Parser.html
|
130
|
+
- doc/Csv2hash/Parser/Collection.html
|
131
|
+
- doc/Csv2hash/Parser/Mapping.html
|
132
|
+
- doc/Csv2hash/StructureValidator.html
|
133
|
+
- doc/Csv2hash/StructureValidator/Deprecation.html
|
134
|
+
- doc/Csv2hash/StructureValidator/MaxColumns.html
|
135
|
+
- doc/Csv2hash/StructureValidator/MinColumns.html
|
136
|
+
- doc/Csv2hash/StructureValidator/ValidationError.html
|
137
|
+
- doc/Csv2hash/StructureValidator/Validator.html
|
138
|
+
- doc/Csv2hash/Validator.html
|
139
|
+
- doc/Csv2hash/Validator/Collection.html
|
140
|
+
- doc/Csv2hash/Validator/Mapping.html
|
141
|
+
- doc/CsvArray.html
|
142
|
+
- doc/Registry.html
|
143
|
+
- doc/_index.html
|
144
|
+
- doc/class_list.html
|
145
|
+
- doc/css/common.css
|
146
|
+
- doc/css/full_list.css
|
147
|
+
- doc/css/style.css
|
148
|
+
- doc/file.README.html
|
149
|
+
- doc/file_list.html
|
150
|
+
- doc/frames.html
|
151
|
+
- doc/index.html
|
152
|
+
- doc/js/app.js
|
153
|
+
- doc/js/full_list.js
|
154
|
+
- doc/js/jquery.js
|
155
|
+
- doc/method_list.html
|
156
|
+
- doc/top-level-namespace.html
|
106
157
|
- lib/csv2hash.rb
|
107
158
|
- lib/csv2hash/adapters/abstract.rb
|
108
159
|
- lib/csv2hash/adapters/base.rb
|
@@ -128,6 +179,7 @@ files:
|
|
128
179
|
- lib/csv2hash/validator/collection.rb
|
129
180
|
- lib/csv2hash/validator/mapping.rb
|
130
181
|
- lib/csv2hash/version.rb
|
182
|
+
- lib/csv2hash/yaml_loader.rb
|
131
183
|
- spec/csv2hash/definition_spec.rb
|
132
184
|
- spec/csv2hash/parser/collection_spec.rb
|
133
185
|
- spec/csv2hash/parser/mapping_spec.rb
|
@@ -136,6 +188,7 @@ files:
|
|
136
188
|
- spec/csv2hash/validator/collection_spec.rb
|
137
189
|
- spec/csv2hash/validator/mapping_spec.rb
|
138
190
|
- spec/csv2hash/validator_spec.rb
|
191
|
+
- spec/csv2hash/yaml_loader_spec.rb
|
139
192
|
- spec/csv2hash_spec.rb
|
140
193
|
- spec/spec_helper.rb
|
141
194
|
homepage: https://github.com/joel/csv2hash
|
@@ -171,5 +224,7 @@ test_files:
|
|
171
224
|
- spec/csv2hash/validator/collection_spec.rb
|
172
225
|
- spec/csv2hash/validator/mapping_spec.rb
|
173
226
|
- spec/csv2hash/validator_spec.rb
|
227
|
+
- spec/csv2hash/yaml_loader_spec.rb
|
174
228
|
- spec/csv2hash_spec.rb
|
175
229
|
- spec/spec_helper.rb
|
230
|
+
has_rdoc:
|