reconciler 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 698a668e5fb5e696fd921efe9b2a46dba7fc5f33
4
+ data.tar.gz: d705035a0a7c9b5e81efdb2913be548dc7977283
5
+ SHA512:
6
+ metadata.gz: 1d748abd20f25e5e0a3cf4cf5051dd96ef1fe97cd71a5003ca9232610e8218cd0864a533870539e9c96a53ee30e9753d69b42411e4fef06eb6aefacee4a4b672
7
+ data.tar.gz: 660a15d7a07833cd788e76ac98f52f24d01ca64ddb0c1bc4ab146f1154b3ecdd08916c4c1fad9bea4d734aa70ff791c4e962e7b395c8fdca4dfc3171ec689a5b
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ #ruby=ruby-2.0.0
2
+ #ruby-gemset=csvlintrb
3
+
4
+ source 'https://rubygems.org'
5
+
6
+ # Specify your gem's dependencies in csvlint.rb.gemspec
7
+ gemspec
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ reconciler (0.0.1)
5
+ json
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.3.5)
11
+ coderay (1.1.0)
12
+ crack (0.4.1)
13
+ safe_yaml (~> 0.9.0)
14
+ diff-lcs (1.2.5)
15
+ docile (1.1.1)
16
+ json (1.7.7)
17
+ method_source (0.8.2)
18
+ multi_json (1.8.2)
19
+ pry (0.9.12.4)
20
+ coderay (~> 1.0)
21
+ method_source (~> 0.8)
22
+ slop (~> 3.4)
23
+ rake (10.1.1)
24
+ rspec (2.14.1)
25
+ rspec-core (~> 2.14.0)
26
+ rspec-expectations (~> 2.14.0)
27
+ rspec-mocks (~> 2.14.0)
28
+ rspec-core (2.14.7)
29
+ rspec-expectations (2.14.4)
30
+ diff-lcs (>= 1.1.3, < 2.0)
31
+ rspec-mocks (2.14.4)
32
+ safe_yaml (0.9.7)
33
+ simplecov (0.8.2)
34
+ docile (~> 1.1.0)
35
+ multi_json
36
+ simplecov-html (~> 0.8.0)
37
+ simplecov-html (0.8.0)
38
+ simplecov-rcov (0.2.3)
39
+ simplecov (>= 0.4.1)
40
+ slop (3.4.7)
41
+ webmock (1.16.1)
42
+ addressable (>= 2.2.7)
43
+ crack (>= 0.3.2)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ bundler (~> 1.3)
50
+ pry
51
+ rake
52
+ reconciler!
53
+ rspec
54
+ rspec-expectations
55
+ simplecov
56
+ simplecov-rcov
57
+ webmock
@@ -0,0 +1,22 @@
1
+ ##Copyright (c) 2014 The Open Data Institute
2
+
3
+ #MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,11 @@
1
+ # Reconciler
2
+
3
+ A ruby gem to support building reconciliation APIs
4
+
5
+ ## Contributing
6
+
7
+ 1. Fork it
8
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
9
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
10
+ 4. Push to the branch (`git push origin my-new-feature`)
11
+ 5. Create new Pull Request
@@ -0,0 +1,213 @@
1
+ [![Build Status](http://img.shields.io/travis/theodi/csvlint.rb.svg)](https://travis-ci.org/theodi/csvlint.rb)
2
+ [![Dependency Status](http://img.shields.io/gemnasium/theodi/csvlint.rb.svg)](https://gemnasium.com/theodi/csvlint.rb)
3
+ [![Coverage Status](http://img.shields.io/coveralls/theodi/csvlint.rb.svg)](https://coveralls.io/r/theodi/csvlint.rb)
4
+ [![License](http://img.shields.io/:license-mit-blue.svg)](http://theodi.mit-license.org)
5
+ [![Badges](http://img.shields.io/:badges-5/5-ff6799.svg)](https://github.com/pikesley/badger)
6
+
7
+ # CSV Lint
8
+
9
+ A ruby gem to support validating CSV files to check their syntax and contents.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'csvlint'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install csvlint
24
+
25
+ ## Usage
26
+
27
+ Currently the gem supports retrieving a CSV accessible from a URL, File, or an IO-style object (e.g. StringIO)
28
+
29
+ require 'csvlint'
30
+
31
+ validator = Csvlint::Validator.new( "http://example.org/data.csv" )
32
+ validator = Csvlint::Validator.new( File.new("/path/to/my/data.csv" )
33
+ validator = Csvlint::Validator.new( StringIO.new( my_data_in_a_string ) )
34
+
35
+ When validating from a URL the range of errors and warnings is wider as the library will also check HTTP headers for
36
+ best practices
37
+
38
+ #invoke the validation
39
+ validator.validate
40
+
41
+ #check validation status
42
+ validator.valid?
43
+
44
+ #access array of errors, each is an Csvlint::ErrorMessage object
45
+ validator.errors
46
+
47
+ #access array of warnings
48
+ validator.warnings
49
+
50
+ #access array of information messages
51
+ validator.info_messages
52
+
53
+ #get some information about the CSV file that was validated
54
+ validator.encoding
55
+ validator.content_type
56
+ validator.extension
57
+
58
+ #retrieve HTTP headers from request
59
+ validator.headers
60
+
61
+ ## Controlling CSV Parsing
62
+
63
+ The validator supports configuration of the [CSV Dialect](http://dataprotocols.org/csv-dialect/) used in a data file. This is specified by
64
+ passing an options hash to the constructor:
65
+
66
+ opts = {
67
+ "header" => true,
68
+ "delimiter" => ","
69
+ }
70
+ validator = Csvlint::Validator.new( "http://example.org/data.csv", opts )
71
+
72
+ The options should be a Hash that conforms to the [CSV Dialect](http://dataprotocols.org/csv-dialect/) JSON structure.
73
+
74
+ While these options configure the parser to correctly process the file, the validator will still raise errors or warnings for CSV
75
+ structure that it considers to be invalid, e.g. a missing header or different delimiters.
76
+
77
+ Note that the parser will also check for a `header` parameter on the `Content-Type` header returned when fetching a remote CSV file. As
78
+ specified in [RFC 4180](http://www.ietf.org/rfc/rfc4180.txt) the values for this can be `present` and `absent`, e.g:
79
+
80
+ Content-Type: text/csv; header=present
81
+
82
+ ## Error Reporting
83
+
84
+ The validator provides feedback on a validation result using instances of `Csvlint::ErrorMessage`. Errors are divided into errors, warnings and information
85
+ messages. A validation attempt is successful if there are no errors.
86
+
87
+ Messages provide context including:
88
+
89
+ * `category` has a symbol that indicates the category or error/warning: `:structure` (well-formedness issues), `:schema` (schema validation), `:context` (publishing metadata, e.g. content type)
90
+ * `type` has a symbol that indicates the type of error or warning being reported
91
+ * `row` holds the line number of the problem
92
+ * `column` holds the column number of the issue
93
+ * `content` holds the contents of the row that generated the error or warning
94
+
95
+ ## Errors
96
+
97
+ The following types of error can be reported:
98
+
99
+ * `:wrong_content_type` -- content type is not `text/csv`
100
+ * `:ragged_rows` -- row has a different number of columns (than the first row in the file)
101
+ * `:blank_rows` -- completely empty row, e.g. blank line or a line where all column values are empty
102
+ * `:invalid_encoding` -- encoding error when parsing row, e.g. because of invalid characters
103
+ * `:not_found` -- HTTP 404 error when retrieving the data
104
+ * `:stray_quote` -- missing or stray quote
105
+ * `:unclosed_quote` -- unclosed quoted field
106
+ * `:whitespace` -- a quoted column has leading or trailing whitespace
107
+ * `:line_breaks` -- line breaks were inconsistent or incorrectly specified
108
+ * `:undeclared_header` -- if there is no machine-readable description of whether a header is present (e.g. in a dialect or `Content-Type` header)
109
+
110
+ ## Warnings
111
+
112
+ The following types of warning can be reported:
113
+
114
+ * `:no_encoding` -- the `Content-Type` header returned in the HTTP request does not have a `charset` parameter
115
+ * `:encoding` -- the character set is not UTF-8
116
+ * `:no_content_type` -- file is being served without a `Content-Type` header
117
+ * `:excel` -- no `Content-Type` header and the file extension is `.xls`
118
+ * `:check_options` -- CSV file appears to contain only a single column
119
+ * `:inconsistent_values` -- inconsistent values in the same column. Reported if <90% of values seem to have same data type (either numeric or alphanumeric including punctuation)
120
+ * `:empty_column_name` -- a column in the CSV header has an empty name
121
+ * `:duplicate_column_name` -- a column in the CSV header has a duplicate name
122
+
123
+ ## Information Messages
124
+
125
+ There are also information messages available:
126
+
127
+ * `:nonrfc_line_breaks` -- uses non-CRLF line breaks, so doesn't conform to RFC4180.
128
+ * `:assumed_header` -- the validator has assumed that a header is present
129
+
130
+ ## Schema Validation
131
+
132
+ The library supports validating data against a schema. A schema configuration can be provided as a Hash or parsed from JSON. The structure currently
133
+ follows JSON Table Schema with some extensions.
134
+
135
+ An example schema file is:
136
+
137
+ {
138
+ "fields": [
139
+ {
140
+ "name": "id",
141
+ "constraints": { "required": true }
142
+ },
143
+ {
144
+ "name": "price",
145
+ "constraints": { "required": true, "minLength": 1 }
146
+ },
147
+ {
148
+ "name": "postcode",
149
+ "constraints": {
150
+ "required": true,
151
+ "pattern": "[A-Z]{1,2}[0-9][0-9A-Z]? ?[0-9][A-Z]{2}"
152
+ }
153
+ }
154
+ ]
155
+ }
156
+
157
+ Parsing and validating with a schema:
158
+
159
+ schema = Schema.load_from_json_table(uri)
160
+ validator = Csvlint::Validator.new( "http://example.org/data.csv", nil, schema )
161
+
162
+ Supported constraints:
163
+
164
+ * `required` -- there must be a value for this field in every row
165
+ * `unique` -- the values in every row should be unique
166
+ * `minLength` -- minimum number of characters in the value
167
+ * `maxLength` -- maximum number of characters in the value
168
+ * `pattern` -- values must match the provided regular expression
169
+ * `type` -- specifies an XML Schema data type. Values of the column must be a valid value for that type
170
+ * `minimum` -- specify a minimum range for values, the value will be parsed as specified by `type`
171
+ * `maximum` -- specify a maximum range for values, the value will be parsed as specified by `type`
172
+ * `datePattern` -- specify a `strftime` compatible date pattern to be used when parsing date values and min/max constraints
173
+
174
+ Supported data types (this is still a work in progress):
175
+
176
+ * String -- `http://www.w3.org/2001/XMLSchema#string` (effectively a no-op)
177
+ * Integer -- `http://www.w3.org/2001/XMLSchema#integer` or `http://www.w3.org/2001/XMLSchema#int`
178
+ * Float -- `http://www.w3.org/2001/XMLSchema#float`
179
+ * Double -- `http://www.w3.org/2001/XMLSchema#double`
180
+ * URI -- `http://www.w3.org/2001/XMLSchema#anyURI`
181
+ * Boolean -- `http://www.w3.org/2001/XMLSchema#boolean`
182
+ * Non Positive Integer -- `http://www.w3.org/2001/XMLSchema#nonPositiveInteger`
183
+ * Positive Integer -- `http://www.w3.org/2001/XMLSchema#positiveInteger`
184
+ * Non Negative Integer -- `http://www.w3.org/2001/XMLSchema#nonNegativeInteger`
185
+ * Negative Integer -- `http://www.w3.org/2001/XMLSchema#negativeInteger`
186
+ * Date -- `http://www.w3.org/2001/XMLSchema#date`
187
+ * Date Time -- `http://www.w3.org/2001/XMLSchema#dateTime`
188
+ * Year -- `http://www.w3.org/2001/XMLSchema#gYear`
189
+ * Year Month -- `http://www.w3.org/2001/XMLSchema#gYearMonth`
190
+ * Time -- `http://www.w3.org/2001/XMLSchema#time`
191
+
192
+ Use of an unknown data type will result in the column failing to validate.
193
+
194
+ Schema validation provides some additional types of error and warning messages:
195
+
196
+ * `:missing_value` (error) -- a column marked as `required` in the schema has no value
197
+ * `:min_length` (error) -- a column with a `minLength` constraint has a value that is too short
198
+ * `:max_length` (error) -- a column with a `maxLength` constraint has a value that is too long
199
+ * `:pattern` (error) -- a column with a `pattern` constraint has a value that doesn't match the regular expression
200
+ * `:header_name` (warning) -- the header in the CSV has a column name that doesn't match the schema
201
+ * `:missing_column` (warning) -- a row in the CSV file has a missing column, that is specified in the schema. This is a warning only, as it may be legitimate
202
+ * `:extra_column` (warning) -- a row in the CSV file has extra column.
203
+ * `:unique` (error) -- a column with a `unique` constraint contains non-unique values
204
+ * `:below_minimum` (error) -- a column with a `minimum` constraint contains a value that is below the minimum
205
+ * `:above_maximum` (error) -- a column with a `maximum` constraint contains a value that is above the maximum
206
+
207
+ ## Contributing
208
+
209
+ 1. Fork it
210
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
211
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
212
+ 4. Push to the branch (`git push origin my-new-feature`)
213
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ $:.unshift File.join( File.dirname(__FILE__), "lib")
4
+
5
+ require 'rubygems'
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task :default => [:spec]
@@ -0,0 +1 @@
1
+ require "json"
@@ -0,0 +1,3 @@
1
+ module Reconciler
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'reconciler/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "reconciler"
9
+ spec.version = Reconciler::VERSION
10
+ spec.authors = ["ldodds"]
11
+ spec.email = ["leigh@ldodds.com"]
12
+ spec.description = %q{Reconciliation API Framework}
13
+ spec.summary = %q{Reconcilation API Framework}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "json"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "simplecov"
27
+ spec.add_development_dependency "simplecov-rcov"
28
+ spec.add_development_dependency "webmock"
29
+ spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "rspec-expectations"
31
+ spec.add_development_dependency "pry"
32
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reconciler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ldodds
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov-rcov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-expectations
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Reconciliation API Framework
140
+ email:
141
+ - leigh@ldodds.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - Gemfile
147
+ - Gemfile.lock
148
+ - LICENSE.md
149
+ - README.md
150
+ - README.md~
151
+ - Rakefile
152
+ - lib/reconciler.rb
153
+ - lib/reconciler/version.rb
154
+ - reconciler.gemspec
155
+ homepage: ''
156
+ licenses:
157
+ - MIT
158
+ metadata: {}
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.2.1
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: Reconcilation API Framework
179
+ test_files: []