cid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cid.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 pezholio
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Cid
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cid'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cid
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/cid.rb ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.join( File.dirname(__FILE__), "..", "lib")
3
+
4
+ require 'cid'
5
+ require 'colorize'
6
+
7
+ def print_error(index, error, color=:red)
8
+ location = ""
9
+ location += error.row.to_s if error.row
10
+ location += "#{error.row ? "," : ""}#{error.column.to_s}" if error.column
11
+ if error.row || error.column
12
+ location = "#{error.row ? "Row" : "Column"}: #{location}"
13
+ end
14
+ puts "#{index+1}. #{error.type}. #{location}".colorize(color)
15
+ end
16
+
17
+ if ARGV[0] == "validate"
18
+
19
+ if ARGV[1]
20
+ source = ARGV[1]
21
+ else
22
+ source = "."
23
+ end
24
+
25
+ validation = Cid::Validation.validate(source)
26
+
27
+ code = 0
28
+
29
+ validation.each do |k,v|
30
+
31
+ puts "#{k} is #{(v[:errors] + v[:warnings]).count == 0 ? "VALID".green : "INVALID".red}"
32
+
33
+ if v[:errors].length > 0
34
+ v[:errors].each_with_index do |error, i|
35
+ print_error(i, error)
36
+ end
37
+ end
38
+
39
+ if v[:warnings].length > 0
40
+ v[:warnings].each_with_index do |error, i|
41
+ print_error(i, error)
42
+ end
43
+ end
44
+
45
+ code = 1 if (v[:errors] + v[:warnings]).count > 0
46
+
47
+ end
48
+
49
+ exit code
50
+
51
+ end
data/cid.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cid"
8
+ spec.version = Cid::VERSION
9
+ spec.authors = ["pezholio"]
10
+ spec.email = ["pezholio@gmail.com"]
11
+ spec.summary = "Tools to allow continuous integration when collaborating on data in Github"
12
+ spec.homepage = "http://github.com/theodi/datapackage.rb"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "csvlint"
21
+ spec.add_dependency "colorize"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "coveralls"
28
+
29
+ end
@@ -0,0 +1,34 @@
1
+ require 'csvlint'
2
+
3
+ module Cid
4
+
5
+ class Validation
6
+
7
+ def self.validate(path)
8
+ result = {}
9
+
10
+ paths = Dir.glob("#{path}/**")
11
+
12
+ paths.each do |path|
13
+ begin
14
+ schema = Csvlint::Schema.load_from_json_table(File.new(Dir["#{path}/schema.json"][0]))
15
+ rescue
16
+ # Error! No schema in place!
17
+ end
18
+
19
+ Dir["#{path}/*.csv"].each do |csv|
20
+ validator = Csvlint::Validator.new(File.new(csv), nil, schema)
21
+ ref = csv.split("/").last(2).join("/")
22
+ result[ref] = {}
23
+
24
+ result[ref][:errors] = validator.errors
25
+ result[ref][:warnings] = validator.warnings
26
+ end
27
+ end
28
+
29
+ result
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,3 @@
1
+ module Cid
2
+ VERSION = "0.0.1"
3
+ end
data/lib/cid.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "cid/version"
2
+ require "cid/validation"
@@ -0,0 +1,55 @@
1
+ {
2
+ "title": "UK European Election Data - Votes",
3
+ "description": "Votes per party by region in a UK European Election",
4
+ "fields": [
5
+ {
6
+ "name": "Poll Date",
7
+ "type": "date",
8
+ "description": "Date the poll took place",
9
+ "format": "yyyy-mm-dd"
10
+ },
11
+ {
12
+ "name": "Area",
13
+ "type": "string",
14
+ "description": "The name of the area which the result is for",
15
+ "required": true
16
+ },
17
+ {
18
+ "name": "Area Code",
19
+ "type": "number",
20
+ "description": "The Office of National Statistics code for the area",
21
+ "pattern": "E1500000(0-9)",
22
+ "required": true
23
+ },
24
+ {
25
+ "name": "Area URL",
26
+ "type": "string",
27
+ "description": "",
28
+ "required": true,
29
+ "pattern": "http://statistics.data.gov.uk/doc/statistical-geography/E1500000(0-9)"
30
+ },
31
+ {
32
+ "name": "Party",
33
+ "type": "string",
34
+ "description": "",
35
+ "required": true
36
+ },
37
+ {
38
+ "name": "Party ID",
39
+ "type": "string",
40
+ "description": "",
41
+ "required": true,
42
+ "pattern": "PPm? [0-9]+"
43
+ },
44
+ {
45
+ "name": "Votes",
46
+ "type": "integer",
47
+ "description": ""
48
+ },
49
+ {
50
+ "name": "Ballots Rejected",
51
+ "type": "integer",
52
+ "description": ""
53
+ }
54
+ ]
55
+ }
@@ -0,0 +1,13 @@
1
+ Poll Date,Region,Area Code,Area URL,Party,Party ID,Votes,Ballots Rejected
2
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,British National Party ,PP 106,121967,9216
3
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Christian Party,PP 1992,18784,9217
4
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Conservative Party ,PP 52,396847,9218
5
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,English Democrats Party,PP 17,32455,9219
6
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Jury Team,PP 999,8721,9220
7
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Liberal Democrats,PP 90,170246,9221
8
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,No2EU: Yes to Democracy,PP 2164,13415,9222
9
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Pro Democracy: Libertas.eu ,PP 999,6961,9223
10
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Socialist Labour Party,PP 73,14724,9224
11
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,The Green Party,PP 63,88244,9225
12
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,The Labour Party,PP 53,240201,9226
13
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,United Kingdom Independence Party,PP 85,300471,9227
@@ -0,0 +1,55 @@
1
+ {
2
+ "title": "UK European Election Data - Votes",
3
+ "description": "Votes per party by region in a UK European Election",
4
+ "fields": [
5
+ {
6
+ "name": "Poll Date",
7
+ "type": "date",
8
+ "description": "Date the poll took place",
9
+ "format": "yyyy-mm-dd"
10
+ },
11
+ {
12
+ "name": "Area",
13
+ "type": "string",
14
+ "description": "The name of the area which the result is for",
15
+ "required": true
16
+ },
17
+ {
18
+ "name": "Area Code",
19
+ "type": "number",
20
+ "description": "The Office of National Statistics code for the area",
21
+ "pattern": "E1500000(0-9)",
22
+ "required": true
23
+ },
24
+ {
25
+ "name": "Area URL",
26
+ "type": "string",
27
+ "description": "",
28
+ "required": true,
29
+ "pattern": "http://statistics.data.gov.uk/doc/statistical-geography/E1500000(0-9)"
30
+ },
31
+ {
32
+ "name": "Party",
33
+ "type": "string",
34
+ "description": "",
35
+ "required": true
36
+ },
37
+ {
38
+ "name": "Party ID",
39
+ "type": "string",
40
+ "description": "",
41
+ "required": true,
42
+ "pattern": "PPm? [0-9]+"
43
+ },
44
+ {
45
+ "name": "Votes",
46
+ "type": "integer",
47
+ "description": ""
48
+ },
49
+ {
50
+ "name": "Ballots Rejected",
51
+ "type": "integer",
52
+ "description": ""
53
+ }
54
+ ]
55
+ }
@@ -0,0 +1,13 @@
1
+ Poll Date,Area,Area Code,Area URL,Party,Party ID,Votes,Ballots Rejected
2
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,British National Party ,PP 106,121967,9216
3
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Christian Party,PP 1992,18784,9217
4
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Conservative Party ,PP 52,396847,9218
5
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,English Democrats Party,PP 17,32455,9219
6
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Jury Team,PP 999,8721,9220
7
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Liberal Democrats,PP 90,170246,9221
8
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,No2EU: Yes to Democracy,PP 2164,13415,9222
9
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Pro Democracy: Libertas.eu ,PP 999,6961,9223
10
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Socialist Labour Party,PP 73,14724,9224
11
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,The Green Party,PP 63,88244,9225
12
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,The Labour Party,PP 53,240201,9226
13
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,United Kingdom Independence Party,PP 85,300471,9227
@@ -0,0 +1,13 @@
1
+ Poll Date,Area,Area Code,Area URL,Party,Party ID,Votes,Ballots Rejected
2
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,British National Party ,PP 106,121967,9216
3
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Christian Party,PP 1992,18784,9217
4
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Conservative Party ,PP 52,396847,9218
5
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,English Democrats Party,PP 17,32455,9219
6
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Jury Team,PP 999,8721,9220
7
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Liberal Democrats,PP 90,170246,9221
8
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,No2EU: Yes to Democracy,PP 2164,13415,9222
9
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Pro Democracy: Libertas.eu ,PP 999,6961,9223
10
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Socialist Labour Party,PP 73,14724,9224
11
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,The Green Party,PP 63,88244,9225
12
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,The Labour Party,PP 53,240201,9226
13
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,United Kingdom Independence Party,PP 85,300471,9227
@@ -0,0 +1,70 @@
1
+ {
2
+ "title": "UK European Election Data - Seats",
3
+ "description": "Seats won by party in a UK European Election",
4
+ "fields": [
5
+ {
6
+ "name": "Poll Date",
7
+ "type": "date",
8
+ "description": "Date the poll took place",
9
+ "format": "yyyy-mm-dd",
10
+ "required": true
11
+ },
12
+ {
13
+ "name": "Area",
14
+ "type": "string",
15
+ "description": "The name of the area which the result is for",
16
+ "required": true
17
+ },
18
+ {
19
+ "name": "Area Code",
20
+ "type": "number",
21
+ "description": "The Office of National Statistics code for the area",
22
+ "required": true,
23
+ "pattern": "E1500000(0-9)"
24
+ },
25
+ {
26
+ "name": "Area URL",
27
+ "type": "string",
28
+ "description": "",
29
+ "required": true,
30
+ "pattern": "http://statistics.data.gov.uk/doc/statistical-geography/E1500000(0-9)"
31
+ },
32
+ {
33
+ "name": "Seat",
34
+ "type": "integer",
35
+ "description": "",
36
+ "required": true
37
+ },
38
+ {
39
+ "name": "Party",
40
+ "type": "string",
41
+ "description": "",
42
+ "required": true
43
+ },
44
+ {
45
+ "name": "Party ID",
46
+ "type": "string",
47
+ "description": "",
48
+ "required": true,
49
+ "pattern": "PPm? [0-9]+"
50
+ },
51
+ {
52
+ "name": "Name",
53
+ "type": "string",
54
+ "description": "Name of the candidate elected to the seat",
55
+ "required": true
56
+ },
57
+ {
58
+ "name": "Address",
59
+ "type": "string",
60
+ "description": "Address of the candidate elected to the seat",
61
+ "required": true
62
+ },
63
+ {
64
+ "name": "Postcode",
65
+ "type": "string",
66
+ "description": "Postcode of the candidate elected to the seat",
67
+ "pattern": "(GIR 0AA)|((([A-Z-[QVX]][0-9][0-9]?)|(([A-Z-[QVX]][A-Z-[IJZ]][0-9][0-9]?)|(([A-Z-[QVX]][0-9][A-HJKSTUW])|([A-Z-[QVX]][A-Z-[IJZ]][0-9][ABEHMNPRVWXY])))) [0-9][A-Z-[CIKMOV]]{2})"
68
+ }
69
+ ]
70
+ }
@@ -0,0 +1,7 @@
1
+ Poll Date,Area,Area Code,Area URL,Seat,Party,Party ID,Name,Address,Postcode
2
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,1,Conservative Party ,PP 52,Philip Charles Bradbourn,"67 Wallheath Crescent, Stonnall, Staffordshire",WS9 9HS
3
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,2,United Kingdom Independence Party,PP 85,Mike Nattrass ,"11 Ladywood Road, Sutton Coldfield",B74 2SW
4
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,3,The Labour Party,PP 53,Michael Maurice Cashman,"94 Narrow Street, London",E14 8BP
5
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,4,Conservative Party ,PP 52,Malcolm John Charles Harbour,"Manor Cottage, Manor Road, Solihull, West Midlands ",B91 2BL
6
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,5,Liberal Democrats,PP 90,Liz Lynne ,"The Old Bakery, East Side, North Littleton",WR11 8QW
7
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,6,United Kingdom Independence Party,PP 85,Nikki Sinclaire,"44 Velsheda Road, Solihull",B90 2JN
@@ -0,0 +1,7 @@
1
+ Poll Date,Area,Area Code,Area URL,Seat,Party,Party ID,Name,Address,Postcode
2
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,1,Conservative Party ,PP 52,Philip Charles Bradbourn,"67 Wallheath Crescent, Stonnall, Staffordshire",WS9 9HS
3
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,2,United Kingdom Independence Party,PP 85,Mike Nattrass ,"11 Ladywood Road, Sutton Coldfield",B74 2SW
4
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,3,The Labour Party,PP 53,Michael Maurice Cashman,"94 Narrow Street, London",E14 8BP
5
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,4,Conservative Party ,PP 52,Malcolm John Charles Harbour,"Manor Cottage, Manor Road, Solihull, West Midlands ",B91 2BL
6
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,5,Liberal Democrats,PP 90,Liz Lynne ,"The Old Bakery, East Side, North Littleton",WR11 8QW
7
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,6,United Kingdom Independence Party,PP 85,Nikki Sinclaire,"44 Velsheda Road, Solihull",B90 2JN
@@ -0,0 +1,55 @@
1
+ {
2
+ "title": "UK European Election Data - Votes",
3
+ "description": "Votes per party by region in a UK European Election",
4
+ "fields": [
5
+ {
6
+ "name": "Poll Date",
7
+ "type": "date",
8
+ "description": "Date the poll took place",
9
+ "format": "yyyy-mm-dd"
10
+ },
11
+ {
12
+ "name": "Area",
13
+ "type": "string",
14
+ "description": "The name of the area which the result is for",
15
+ "required": true
16
+ },
17
+ {
18
+ "name": "Area Code",
19
+ "type": "number",
20
+ "description": "The Office of National Statistics code for the area",
21
+ "pattern": "E1500000(0-9)",
22
+ "required": true
23
+ },
24
+ {
25
+ "name": "Area URL",
26
+ "type": "string",
27
+ "description": "",
28
+ "required": true,
29
+ "pattern": "http://statistics.data.gov.uk/doc/statistical-geography/E1500000(0-9)"
30
+ },
31
+ {
32
+ "name": "Party",
33
+ "type": "string",
34
+ "description": "",
35
+ "required": true
36
+ },
37
+ {
38
+ "name": "Party ID",
39
+ "type": "string",
40
+ "description": "",
41
+ "required": true,
42
+ "pattern": "PPm? [0-9]+"
43
+ },
44
+ {
45
+ "name": "Votes",
46
+ "type": "integer",
47
+ "description": ""
48
+ },
49
+ {
50
+ "name": "Ballots Rejected",
51
+ "type": "integer",
52
+ "description": ""
53
+ }
54
+ ]
55
+ }
@@ -0,0 +1,13 @@
1
+ Poll Date,Area,Area Code,Area URL,Party,Party ID,Votes,Ballots Rejected
2
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,British National Party ,PP 106,121967,9216
3
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Christian Party,PP 1992,18784,9217
4
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Conservative Party ,PP 52,396847,9218
5
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,English Democrats Party,PP 17,32455,9219
6
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Jury Team,PP 999,8721,9220
7
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Liberal Democrats,PP 90,170246,9221
8
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,No2EU: Yes to Democracy,PP 2164,13415,9222
9
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Pro Democracy: Libertas.eu ,PP 999,6961,9223
10
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Socialist Labour Party,PP 73,14724,9224
11
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,The Green Party,PP 63,88244,9225
12
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,The Labour Party,PP 53,240201,9226
13
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,United Kingdom Independence Party,PP 85,300471,9227
@@ -0,0 +1,13 @@
1
+ Poll Date,Area,Area Code,Area URL,Party,Party ID,Votes,Ballots Rejected
2
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,British National Party ,PP 106,121967,9216
3
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Christian Party,PP 1992,18784,9217
4
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Conservative Party ,PP 52,396847,9218
5
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,English Democrats Party,PP 17,32455,9219
6
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Jury Team,PP 999,8721,9220
7
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Liberal Democrats,PP 90,170246,9221
8
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,No2EU: Yes to Democracy,PP 2164,13415,9222
9
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Pro Democracy: Libertas.eu ,PP 999,6961,9223
10
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Socialist Labour Party,PP 73,14724,9224
11
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,The Green Party,PP 63,88244,9225
12
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,The Labour Party,PP 53,240201,9226
13
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,United Kingdom Independence Party,PP 85,300471,9227
@@ -0,0 +1,55 @@
1
+ {
2
+ "title": "UK European Election Data - Votes",
3
+ "description": "Votes per party by region in a UK European Election",
4
+ "fields": [
5
+ {
6
+ "name": "Poll Date",
7
+ "type": "date",
8
+ "description": "Date the poll took place",
9
+ "format": "yyyy-mm-dd"
10
+ },
11
+ {
12
+ "name": "Area",
13
+ "type": "string",
14
+ "description": "The name of the area which the result is for",
15
+ "required": true
16
+ },
17
+ {
18
+ "name": "Area Code",
19
+ "type": "number",
20
+ "description": "The Office of National Statistics code for the area",
21
+ "pattern": "E1500000(0-9)",
22
+ "required": true
23
+ },
24
+ {
25
+ "name": "Area URL",
26
+ "type": "string",
27
+ "description": "",
28
+ "required": true,
29
+ "pattern": "http://statistics.data.gov.uk/doc/statistical-geography/E1500000(0-9)"
30
+ },
31
+ {
32
+ "name": "Party",
33
+ "type": "string",
34
+ "description": "",
35
+ "required": true
36
+ },
37
+ {
38
+ "name": "Party ID",
39
+ "type": "string",
40
+ "description": "",
41
+ "required": true,
42
+ "pattern": "PPm? [0-9]+"
43
+ },
44
+ {
45
+ "name": "Votes",
46
+ "type": "integer",
47
+ "description": ""
48
+ },
49
+ {
50
+ "name": "Ballots Rejected",
51
+ "type": "integer",
52
+ "description": ""
53
+ }
54
+ ]
55
+ }
@@ -0,0 +1,13 @@
1
+ Poll Date,Area,Area Code,Area URL,Party,Party ID,Votes,Ballots Rejected
2
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,British National Party ,PP 106,121967,9216
3
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Christian Party,PP 1992,18784,9217
4
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Conservative Party ,PP 52,396847,9218
5
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,English Democrats Party,PP 17,32455,9219
6
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Jury Team,PP 999,8721,9220
7
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Liberal Democrats,PP 90,170246,9221
8
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,No2EU: Yes to Democracy,PP 2164,13415,9222
9
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Pro Democracy: Libertas.eu ,PP 999,6961,9223
10
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,Socialist Labour Party,PP 73,14724,9224
11
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,The Green Party,PP 63,88244,9225
12
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,The Labour Party,PP 53,240201,9226
13
+ 2009-06-04,West Midlands,E15000005,http://statistics.data.gov.uk/doc/statistical-geography/E15000005,United Kingdom Independence Party,PP 85,300471,9227
@@ -0,0 +1,9 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'cid'
5
+ require 'pry'
6
+
7
+ RSpec.configure do |config|
8
+ config.order = "random"
9
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cid::Validation do
4
+
5
+ it "validates a package with a single file in a single folder" do
6
+ Csvlint::Validator.should_receive(:new).once.and_call_original
7
+
8
+ validation = Cid::Validation.validate(File.join(File.dirname(__FILE__), 'fixtures', 'valid'))
9
+
10
+ validation["votes/votes-1.csv"][:errors].should == []
11
+ validation["votes/votes-1.csv"][:warnings].should == []
12
+ end
13
+
14
+ it "validates a package with multiple files in a single folder" do
15
+ Csvlint::Validator.should_receive(:new).twice.and_call_original
16
+
17
+ validation = Cid::Validation.validate(File.join(File.dirname(__FILE__), 'fixtures', 'multiple_files'))
18
+
19
+ validation["votes/votes-1.csv"][:errors].should == []
20
+ validation["votes/votes-1.csv"][:warnings].should == []
21
+ validation["votes/votes-2.csv"][:errors].should == []
22
+ validation["votes/votes-2.csv"][:warnings].should == []
23
+ end
24
+
25
+ it "validates a package with multiple files in multiple folders" do
26
+ Csvlint::Validator.should_receive(:new).exactly(4).times.and_call_original
27
+
28
+ validation = Cid::Validation.validate(File.join(File.dirname(__FILE__), 'fixtures', 'multiple_folders'))
29
+
30
+ validation["votes/votes-1.csv"][:errors].should == []
31
+ validation["votes/votes-1.csv"][:warnings].should == []
32
+ validation["votes/votes-2.csv"][:errors].should == []
33
+ validation["votes/votes-2.csv"][:warnings].should == []
34
+ validation["seats/seats-1.csv"][:errors].should == []
35
+ validation["seats/seats-1.csv"][:warnings].should == []
36
+ validation["seats/seats-2.csv"][:errors].should == []
37
+ validation["seats/seats-2.csv"][:warnings].should == []
38
+ end
39
+
40
+ it "returns errors for an invalid csv" do
41
+ validation = Cid::Validation.validate(File.join(File.dirname(__FILE__), 'fixtures', 'invalid'))
42
+
43
+ validation["votes/votes-1.csv"][:warnings].count.should == 1
44
+ validation["votes/votes-1.csv"][:warnings].first.category.should == :schema
45
+ validation["votes/votes-1.csv"][:warnings].first.column.should == 2
46
+ end
47
+
48
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - pezholio
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: csvlint
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: colorize
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: pry
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: coveralls
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
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
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description:
127
+ email:
128
+ - pezholio@gmail.com
129
+ executables:
130
+ - cid.rb
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/cid.rb
140
+ - cid.gemspec
141
+ - lib/cid.rb
142
+ - lib/cid/validation.rb
143
+ - lib/cid/version.rb
144
+ - spec/fixtures/invalid/votes/schema.json
145
+ - spec/fixtures/invalid/votes/votes-1.csv
146
+ - spec/fixtures/multiple_files/votes/schema.json
147
+ - spec/fixtures/multiple_files/votes/votes-1.csv
148
+ - spec/fixtures/multiple_files/votes/votes-2.csv
149
+ - spec/fixtures/multiple_folders/seats/schema.json
150
+ - spec/fixtures/multiple_folders/seats/seats-1.csv
151
+ - spec/fixtures/multiple_folders/seats/seats-2.csv
152
+ - spec/fixtures/multiple_folders/votes/schema.json
153
+ - spec/fixtures/multiple_folders/votes/votes-1.csv
154
+ - spec/fixtures/multiple_folders/votes/votes-2.csv
155
+ - spec/fixtures/valid/votes/schema.json
156
+ - spec/fixtures/valid/votes/votes-1.csv
157
+ - spec/spec_helper.rb
158
+ - spec/validate_spec.rb
159
+ homepage: http://github.com/theodi/datapackage.rb
160
+ licenses:
161
+ - MIT
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ! '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 1.8.25
181
+ signing_key:
182
+ specification_version: 3
183
+ summary: Tools to allow continuous integration when collaborating on data in Github
184
+ test_files:
185
+ - spec/fixtures/invalid/votes/schema.json
186
+ - spec/fixtures/invalid/votes/votes-1.csv
187
+ - spec/fixtures/multiple_files/votes/schema.json
188
+ - spec/fixtures/multiple_files/votes/votes-1.csv
189
+ - spec/fixtures/multiple_files/votes/votes-2.csv
190
+ - spec/fixtures/multiple_folders/seats/schema.json
191
+ - spec/fixtures/multiple_folders/seats/seats-1.csv
192
+ - spec/fixtures/multiple_folders/seats/seats-2.csv
193
+ - spec/fixtures/multiple_folders/votes/schema.json
194
+ - spec/fixtures/multiple_folders/votes/votes-1.csv
195
+ - spec/fixtures/multiple_folders/votes/votes-2.csv
196
+ - spec/fixtures/valid/votes/schema.json
197
+ - spec/fixtures/valid/votes/votes-1.csv
198
+ - spec/spec_helper.rb
199
+ - spec/validate_spec.rb