cevennes 0.9.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1fb788c6c511d207dbeb25a03ffb061da5485de2
4
+ data.tar.gz: 9a20b7faae773a410f8c04d919810099529f664d
5
+ SHA512:
6
+ metadata.gz: 33684d80bfff9bab6755492edf1e97f09928d992619f5af5704e962c2f1a160ac110d7f587386b3ad2a5b9a3402247ef9ec11b1a65170c74ba7b016f7933ff1e
7
+ data.tar.gz: c348f6108095abe5c00201ff3ac39948d607cdc7e5f222af64fe4e9f841734625f1a79f31524ba23bd68f7a04cc7b7ebe92f3cf0b758ef385b02d241d6f3dad4
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+
2
+ # CHANGELOG.md
3
+
4
+
5
+ ## cevennes 0.9.0 released 2018-09-03
6
+
7
+ - Implement first version of Cevennes.diff(id, cvs0, cvs1)
8
+
data/CREDITS.md ADDED
@@ -0,0 +1,5 @@
1
+
2
+ # cevennes credits
3
+
4
+ * John Mettraux https://github.com/jmettraux author and maintainer
5
+
data/LICENSE.txt ADDED
@@ -0,0 +1,24 @@
1
+
2
+ Copyright (c) 2018-2018, John Mettraux, jmettraux@gmail.com
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
21
+
22
+
23
+ Made in Japan
24
+
data/Makefile ADDED
@@ -0,0 +1,39 @@
1
+
2
+ ## gem tasks ##
3
+
4
+ NAME = \
5
+ $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name")
6
+ VERSION = \
7
+ $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.version")
8
+
9
+ count_lines:
10
+ find lib -name "*.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
11
+ find spec -name "*_spec.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
12
+ cl: count_lines
13
+
14
+ gemspec_validate:
15
+ @echo "---"
16
+ ruby -e "s = eval(File.read(Dir['*.gemspec'].first)); p s.validate"
17
+ @echo "---"
18
+
19
+ name: gemspec_validate
20
+ @echo "$(NAME) $(VERSION)"
21
+
22
+ cw:
23
+ find lib -name "*.rb" -exec ruby -cw {} \;
24
+
25
+ build: gemspec_validate
26
+ gem build $(NAME).gemspec
27
+ mkdir -p pkg
28
+ mv $(NAME)-$(VERSION).gem pkg/
29
+
30
+ push: build
31
+ gem push pkg/$(NAME)-$(VERSION).gem
32
+
33
+ spec:
34
+ bundle exec rspec
35
+ test: spec
36
+
37
+
38
+ .PHONY: count_lines gemspec_validate name cw build push spec
39
+
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+
2
+ # cevennes
3
+
4
+ [![Build Status](https://secure.travis-ci.org/jmettraux/cevennes.svg)](http://travis-ci.org/jmettraux/cevennes)
5
+ [![Gem Version](https://badge.fury.io/rb/cevennes.svg)](http://badge.fury.io/rb/cevennes)
6
+
7
+ Diffs CSVs by lines, focusing on a single ID
8
+
9
+ ## usage
10
+
11
+ TODO
12
+
13
+ ## LICENSE
14
+
15
+ MIT, see [LICENSE.txt](LICENSE.txt)
16
+
data/cevennes.gemspec ADDED
@@ -0,0 +1,41 @@
1
+
2
+ Gem::Specification.new do |s|
3
+
4
+ s.name = 'cevennes'
5
+
6
+ s.version = File.read(
7
+ File.expand_path('../lib/cevennes.rb', __FILE__)
8
+ ).match(/ VERSION *= *['"]([^'"]+)/)[1]
9
+
10
+ s.platform = Gem::Platform::RUBY
11
+ s.authors = [ 'John Mettraux' ]
12
+ s.email = [ 'jmettraux@gmail.com' ]
13
+ s.homepage = 'http://github.com/jmettraux/cevennes'
14
+ s.license = 'MIT'
15
+ s.summary = 'CSV diff library'
16
+
17
+ s.description = %{
18
+ Diffs CSVs by lines, focusing on a single ID
19
+ }.strip
20
+
21
+ s.metadata = {
22
+ 'changelog_uri' => s.homepage + '/blob/master/CHANGELOG.md'
23
+ }
24
+
25
+ #s.files = `git ls-files`.split("\n")
26
+ s.files = Dir[
27
+ 'README.{md,txt}',
28
+ 'CHANGELOG.{md,txt}', 'CREDITS.{md,txt}', 'LICENSE.{md,txt}',
29
+ 'Makefile',
30
+ 'lib/**/*.rb', #'spec/**/*.rb', 'test/**/*.rb',
31
+ "#{s.name}.gemspec",
32
+ ]
33
+
34
+ #s.add_runtime_dependency 'tzinfo'
35
+ #s.add_runtime_dependency 'raabro', '~> 1.1'
36
+
37
+ s.add_development_dependency 'rspec', '~> 3.7'
38
+
39
+ s.require_path = 'lib'
40
+ end
41
+
data/lib/cevennes.rb ADDED
@@ -0,0 +1,77 @@
1
+
2
+ require 'csv'
3
+
4
+
5
+ module Cevennes
6
+
7
+ VERSION = '0.9.0'
8
+
9
+ class << self
10
+
11
+ def diff(id, csv0, csv1)
12
+
13
+ h0 = hash(id, csv0)
14
+ h1 = hash(id, csv1)
15
+
16
+ ks0 = h0.delete(:keys)
17
+ ks1 = h1.delete(:keys)
18
+
19
+ d =
20
+ h0
21
+ .collect { |k, v|
22
+ v1 = h1[k]
23
+ if v1 == v
24
+ [ '=', v, nil ]
25
+ else
26
+ [ v1 == nil ? '-' : '!', v, v1 ]
27
+ end }
28
+ .compact +
29
+ (h1.keys - h0.keys)
30
+ .collect { |k|
31
+ v = h1[k]
32
+ [ '+', nil, h1[k] ] }
33
+
34
+ s = d.inject({}) { |h, (a, _, _)| h[a] = (h[a] || 0) + 1; h }
35
+ s['l0'] = h0.length - 1
36
+ s['l1'] = h1.length - 1
37
+
38
+ [ [ 'keys', ks0, ks1 ], [ 'stats', s ] ] + d
39
+ end
40
+
41
+ protected
42
+
43
+ def hash(id, csv)
44
+
45
+ csva = ::CSV.parse(reencode(csv))
46
+ .reject { |row| row.compact.empty? }
47
+ .drop_while { |row| ! row.include?(id) }
48
+
49
+ i = csva[0].index(id)
50
+
51
+ csva[1..-1]
52
+ .inject({ keys: csva[0] }) { |h, row|
53
+ if row.compact.length > 1
54
+ k = row[i]
55
+ h[k] = row if k
56
+ end
57
+ h }
58
+ end
59
+
60
+ #def deflate(row)
61
+ # ::CSV.generate(encoding: 'UTF-8') { |csv| csv << row }.strip
62
+ #end
63
+
64
+ def reencode(s)
65
+
66
+ #s = unzip(s) if s[0, 2] == 'PK'
67
+ # no dependency on rubyzip
68
+
69
+ %w[ Windows-1252 ISO-8859-1 UTF-8 ].each do |e|
70
+ ss = s.force_encoding(e).encode('UTF-8') rescue nil
71
+ break ss if ss
72
+ nil
73
+ end
74
+ end
75
+ end
76
+ end
77
+
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cevennes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - John Mettraux
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.7'
27
+ description: Diffs CSVs by lines, focusing on a single ID
28
+ email:
29
+ - jmettraux@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - CREDITS.md
36
+ - LICENSE.txt
37
+ - Makefile
38
+ - README.md
39
+ - cevennes.gemspec
40
+ - lib/cevennes.rb
41
+ homepage: http://github.com/jmettraux/cevennes
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ changelog_uri: http://github.com/jmettraux/cevennes/blob/master/CHANGELOG.md
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.6.14.1
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: CSV diff library
66
+ test_files: []