cevennes 1.1.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/LICENSE.txt +1 -1
- data/Makefile +1 -1
- data/README.md +41 -1
- data/lib/cevennes.rb +29 -14
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 435cddee7086da63e735457390edf766d42522bf58626b95ead034c418899719
|
4
|
+
data.tar.gz: 20f5371e968decbfc05d062d44ae2cef6f1856716a9e58d321133b6d3089267e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac1aa7f98147a393812a2fec1fdf6e6c714d35a5e325a7a2912f484db7d59212ee66daed23fdbe0013d11b18e737ba2b5e7f9527021ef7300cc9742c0313f80f
|
7
|
+
data.tar.gz: 44b7de7c27260dd623a466c880e4f9c789cf429efc6aa53671f092bfd9449f5d7c5841796da5b517faa34f9dfad202527b98ff8816b940ab4e345e0bfeb4f81b
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,23 @@
|
|
2
2
|
# CHANGELOG.md
|
3
3
|
|
4
4
|
|
5
|
+
## cevennes 1.3.0 released 2022-07-24
|
6
|
+
|
7
|
+
- Diff already parsed CSV as well
|
8
|
+
|
9
|
+
|
10
|
+
## cevennes 1.2.0 released 2022-07-05
|
11
|
+
|
12
|
+
- Introduce `drop_equals: true`
|
13
|
+
|
14
|
+
|
15
|
+
## cevennes 1.1.1 released 2021-02-25
|
16
|
+
|
17
|
+
- Refine UTF-8 re-encoding
|
18
|
+
- Fix `ignore_key_case: true` :-(
|
19
|
+
- Clarify reencode
|
20
|
+
|
21
|
+
|
5
22
|
## cevennes 1.1.0 released 2021-02-24
|
6
23
|
|
7
24
|
- Introduce `ignore_key_case: true`
|
data/LICENSE.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
Copyright (c) 2018-
|
2
|
+
Copyright (c) 2018-2022, John Mettraux, jmettraux@gmail.com
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
data/Makefile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
# cevennes
|
3
3
|
|
4
|
-
[![
|
4
|
+
[![tests](https://github.com/jmettraux/cevennes/workflows/test/badge.svg)](https://github.com/jmettraux/cevennes/actions)
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/cevennes.svg)](http://badge.fury.io/rb/cevennes)
|
6
6
|
|
7
7
|
Diffs CSVs by lines, focusing on a single ID
|
@@ -56,6 +56,46 @@ The second entry is a summary of the changes, altered `!` line count, removed `-
|
|
56
56
|
|
57
57
|
The remaining entries are the (non-)changes themselves, from line 1 to the end.
|
58
58
|
|
59
|
+
Since 1.3.0, Cevennes accepts CSV strings and parsed CSV (array of arrays).
|
60
|
+
|
61
|
+
|
62
|
+
### drop_equals: true
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
require 'cevennes'
|
66
|
+
|
67
|
+
cvs0 = %{
|
68
|
+
id,name,age
|
69
|
+
0,John,33
|
70
|
+
1,Jean-Baptiste,43
|
71
|
+
3,Luke,21
|
72
|
+
}.strip + "\n"
|
73
|
+
cvs1 = %{
|
74
|
+
id,name,age
|
75
|
+
0,John,33
|
76
|
+
1,Jean-Baptiste,44
|
77
|
+
4,Matthew,20
|
78
|
+
}.strip + "\n"
|
79
|
+
|
80
|
+
d = Cevennes.diff('id', cvs0, cvs1, drop_equals: true)
|
81
|
+
# ==>
|
82
|
+
[
|
83
|
+
[ 'keys', 1, [ 'id', 'name', 'age' ],
|
84
|
+
1, [ 'id', 'name', 'age' ] ],
|
85
|
+
[ 'stats',
|
86
|
+
{ '=' => 1, '!' => 1, '-' => 1, '+' => 1,
|
87
|
+
'l0' => 3, 'l1' => 3 } ],
|
88
|
+
[ '!', 3, [ '1', 'Jean-Baptiste', '43' ],
|
89
|
+
3, [ '1', 'Jean-Baptiste', '44' ] ],
|
90
|
+
[ '-', 4, [ '3', 'Luke', '21'],
|
91
|
+
-1, nil ],
|
92
|
+
[ '+', -1, nil,
|
93
|
+
4, [ '4', 'Matthew', '20' ] ]
|
94
|
+
]
|
95
|
+
#
|
96
|
+
# the "=" entries are not included
|
97
|
+
```
|
98
|
+
|
59
99
|
|
60
100
|
## LICENSE
|
61
101
|
|
data/lib/cevennes.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
require 'csv'
|
3
4
|
|
4
5
|
|
5
6
|
module Cevennes
|
6
7
|
|
7
|
-
VERSION = '1.
|
8
|
+
VERSION = '1.3.0'
|
8
9
|
|
9
10
|
class << self
|
10
11
|
|
@@ -39,6 +40,8 @@ module Cevennes
|
|
39
40
|
s['l0'] = h0.length
|
40
41
|
s['l1'] = h1.length
|
41
42
|
|
43
|
+
d = d.reject { |e| e[0] == '=' } if opts[:drop_equals]
|
44
|
+
|
42
45
|
[ [ 'keys', *ks0, *ks1 ], [ 'stats', s ] ] + d
|
43
46
|
end
|
44
47
|
|
@@ -49,29 +52,28 @@ module Cevennes
|
|
49
52
|
row.collect { |cell| cell.is_a?(String) ? cell.strip : cell }
|
50
53
|
end
|
51
54
|
|
52
|
-
|
53
|
-
|
54
|
-
IDENTITY =
|
55
|
-
lambda { |x| x }
|
55
|
+
DOWNCASE = lambda { |x| x.respond_to?(:downcase) ? x.downcase : x }
|
56
|
+
IDENTITY = lambda { |x| x }
|
56
57
|
|
57
58
|
def hash(version, id, csv, opts)
|
58
59
|
|
59
|
-
d = opts[:ignore_key_case] ?
|
60
|
+
d = opts[:ignore_key_case] ? DOWNCASE : IDENTITY
|
61
|
+
did = d[id]
|
60
62
|
|
61
|
-
csva =
|
63
|
+
csva = parse(csv)
|
62
64
|
.each_with_index.collect { |row, i| [ 1 + i, strip(row) ] }
|
63
65
|
.reject { |i, row| row.compact.empty? }
|
64
|
-
.drop_while { |i, row| ! row.find { |cell| d[cell] ==
|
66
|
+
.drop_while { |i, row| ! row.find { |cell| d[cell] == did } }
|
65
67
|
|
66
68
|
fail ::IndexError.new("id #{id.inspect} not found in #{version} CSV") \
|
67
69
|
if csva.empty?
|
68
70
|
|
69
71
|
csva[0][1] =
|
70
72
|
opts[:ignore_key_case] ?
|
71
|
-
csva[0][1].collect { |c|
|
73
|
+
csva[0][1].collect { |c| DOWNCASE[c] } :
|
72
74
|
csva[0][1]
|
73
75
|
|
74
|
-
idi = csva[0][1].index(
|
76
|
+
idi = csva[0][1].index(did)
|
75
77
|
|
76
78
|
csva[1..-1]
|
77
79
|
.inject({ keys: csva[0] }) { |h, (i, row)|
|
@@ -82,20 +84,33 @@ module Cevennes
|
|
82
84
|
h }
|
83
85
|
end
|
84
86
|
|
87
|
+
def parse(csv)
|
88
|
+
|
89
|
+
return csv if csv.is_a?(Array)
|
90
|
+
::CSV.parse(reencode(csv))
|
91
|
+
end
|
92
|
+
|
85
93
|
#def deflate(row)
|
86
94
|
# ::CSV.generate(encoding: 'UTF-8') { |csv| csv << row }.strip
|
87
95
|
#end
|
88
96
|
|
97
|
+
ENCODINGS = %w[ Windows-1252 ISO-8859-1 UTF-8 ].freeze
|
98
|
+
|
89
99
|
def reencode(s)
|
90
100
|
|
91
101
|
#s = unzip(s) if s[0, 2] == 'PK'
|
92
102
|
# no dependency on rubyzip
|
93
103
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
104
|
+
#return s if s.encoding == Encoding::UTF_8
|
105
|
+
# NO! have to force_encoding for UTF-8 as well!
|
106
|
+
|
107
|
+
s = s.dup if s.frozen?
|
108
|
+
|
109
|
+
ENCODINGS.each do |e|
|
110
|
+
(return s.force_encoding(e).encode('UTF-8')) rescue nil
|
98
111
|
end
|
112
|
+
|
113
|
+
nil
|
99
114
|
end
|
100
115
|
end
|
101
116
|
end
|
metadata
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cevennes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: rspec
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '3.7'
|
20
|
-
|
19
|
+
name: rspec
|
21
20
|
prerelease: false
|
21
|
+
type: :development
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
@@ -47,7 +47,7 @@ metadata:
|
|
47
47
|
bug_tracker_uri: https://github.com/jmettraux/cevennes/issues
|
48
48
|
homepage_uri: https://github.com/jmettraux/cevennes
|
49
49
|
source_code_uri: https://github.com/jmettraux/cevennes
|
50
|
-
post_install_message:
|
50
|
+
post_install_message:
|
51
51
|
rdoc_options: []
|
52
52
|
require_paths:
|
53
53
|
- lib
|
@@ -62,8 +62,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '0'
|
64
64
|
requirements: []
|
65
|
-
rubygems_version: 3.
|
66
|
-
signing_key:
|
65
|
+
rubygems_version: 3.2.3
|
66
|
+
signing_key:
|
67
67
|
specification_version: 4
|
68
68
|
summary: CSV diff library
|
69
69
|
test_files: []
|