cevennes 0.10.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e8fcfbf02c5a728c9a6364a0fe67a61003fa18fa
4
- data.tar.gz: 72361059d05b8c7cca589fa099d4e92a58ca704d
2
+ SHA256:
3
+ metadata.gz: '0885436a7e993e83fcef22afb0605648f92405916461a1fdc3d36c144c67530d'
4
+ data.tar.gz: dd03ef25ed11cea3be74301d4bc147da9108e91e477066d4790f3906e819f67b
5
5
  SHA512:
6
- metadata.gz: fd04c1d5c12954d091a75b55ccb0078757a35bfc1d7d7dc6fcf2cf3d23ecb6929ec47d05adbfc13be1646a4ca6040a05135b9ce4664a5f5947b5413e01bf4fd0
7
- data.tar.gz: ee72cda27967a186dfea52a61ef67256b69f3d56ec95c0c3d0e61bc1084a74a35a59e3025a8a5666e29e7ebfc649c8c6d48a16dda7a64bc4919fbeee255252ee
6
+ metadata.gz: 9a9c66767526700a4c699fc61f3c938e8724a86dbc8662548bd611fb0b02fcddf1ec10c6e7a8acfcb24bd04659dc5eb20b3872a81f0866475d6c20a6ab1eb815
7
+ data.tar.gz: 14e19d5de67104106a904e58c4678a5243dce467e7b26388c9e95d7fd2d4ef8821ae5c4f0c8b3ba488081d8819d2919d3ec418ca523304c95a2a10d82fb7340c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## cevennes 1.1.0 released 2021-02-24
6
+
7
+ - Introduce `ignore_key_case: true`
8
+
9
+
10
+ ## cevennes 1.0.0 released 2018-09-07
11
+
12
+ - Align the "keys" entry on the =+-! entries
13
+
14
+
15
+ ## cevennes 0.13.0 released 2018-09-07
16
+
17
+ - Trim cells and keys
18
+
19
+
20
+ ## cevennes 0.12.0 released 2018-09-06
21
+
22
+ - Fail with IndexError on missing id in CSV old or new
23
+
24
+
25
+ ## cevennes 0.11.0 released 2018-09-06
26
+
27
+ - Fix l0 and l1 stats
28
+
29
+
5
30
  ## cevennes 0.10.0 released 2018-09-03
6
31
 
7
32
  - Weave in additions at the right spot
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2018-2018, John Mettraux, jmettraux@gmail.com
2
+ Copyright (c) 2018-2021, 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/README.md CHANGED
@@ -6,16 +6,56 @@
6
6
 
7
7
  Diffs CSVs by lines, focusing on a single ID
8
8
 
9
+
9
10
  ## usage
10
11
 
11
- TODO
12
+ Given two CSV strings and an identifier name (a column name), cevennes may compute a diff:
13
+ ```ruby
14
+ require 'cevennes'
15
+
16
+ cvs0 = %{
17
+ id,name,age
18
+ 0,John,33
19
+ 1,Jean-Baptiste,43
20
+ 3,Luke,21
21
+ }.strip + "\n"
22
+ cvs1 = %{
23
+ id,name,age
24
+ 0,John,33
25
+ 1,Jean-Baptiste,44
26
+ 4,Matthew,20
27
+ }.strip + "\n"
28
+
29
+ d = Cevennes.diff('id', cvs0, cvs1)
30
+
31
+ #d = Cevennes.diff('id', cvs0, cvs1, ignore_key_case: true)
32
+ # when the key case should be ignored ("Id" == "id")
12
33
  ```
13
- csv0 = %{
14
- }
15
- csv1 = %{
16
- }
17
- pp Cevennes.diff('ISIN', csv0, csv1)
34
+
35
+ `d` will yield:
36
+ ```ruby
37
+ [
38
+ [ 'keys', 1, [ 'id', 'name', 'age' ],
39
+ 1, [ 'id', 'name', 'age' ] ],
40
+ [ 'stats',
41
+ { '=' => 1, '!' => 1, '-' => 1, '+' => 1,
42
+ 'l0' => 3, 'l1' => 3 } ],
43
+ [ '=', 2, [ '0', 'John', '33'],
44
+ 2, nil ],
45
+ [ '!', 3, [ '1', 'Jean-Baptiste', '43' ],
46
+ 3, [ '1', 'Jean-Baptiste', '44' ] ],
47
+ [ '-', 4, [ '3', 'Luke', '21'],
48
+ -1, nil ],
49
+ [ '+', -1, nil,
50
+ 4, [ '4', 'Matthew', '20' ] ]
51
+ ]
18
52
  ```
53
+ It's a list where the first entry is a recap of the keys used in the old and the new CSV strings (the integer is the line number (starting at 1) where the keys where found.
54
+
55
+ The second entry is a summary of the changes, altered `!` line count, removed `-` line count, added `+` line count, old length `l0`, new length `l1`, and unchanged `=` line count.
56
+
57
+ The remaining entries are the (non-)changes themselves, from line 1 to the end.
58
+
19
59
 
20
60
  ## LICENSE
21
61
 
data/cevennes.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.authors = [ 'John Mettraux' ]
12
12
  s.email = [ 'jmettraux@gmail.com' ]
13
- s.homepage = 'http://github.com/jmettraux/cevennes'
13
+ s.homepage = 'https://github.com/jmettraux/cevennes'
14
14
  s.license = 'MIT'
15
15
  s.summary = 'CSV diff library'
16
16
 
@@ -19,7 +19,13 @@ Diffs CSVs by lines, focusing on a single ID
19
19
  }.strip
20
20
 
21
21
  s.metadata = {
22
- 'changelog_uri' => s.homepage + '/blob/master/CHANGELOG.md'
22
+ 'changelog_uri' => s.homepage + '/blob/master/CHANGELOG.md',
23
+ 'documentation_uri' => s.homepage,
24
+ 'bug_tracker_uri' => s.homepage + '/issues',
25
+ #'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/floraison',
26
+ 'homepage_uri' => s.homepage,
27
+ 'source_code_uri' => s.homepage,
28
+ #'wiki_uri' => s.homepage + '/wiki',
23
29
  }
24
30
 
25
31
  #s.files = `git ls-files`.split("\n")
data/lib/cevennes.rb CHANGED
@@ -4,14 +4,14 @@ require 'csv'
4
4
 
5
5
  module Cevennes
6
6
 
7
- VERSION = '0.10.0'
7
+ VERSION = '1.1.0'
8
8
 
9
9
  class << self
10
10
 
11
- def diff(id, csv0, csv1)
11
+ def diff(id, csv0, csv1, opts={})
12
12
 
13
- h0 = hash(id, csv0)
14
- h1 = hash(id, csv1)
13
+ h0 = hash('old', id, csv0, opts)
14
+ h1 = hash('new', id, csv1, opts)
15
15
 
16
16
  ks0 = h0.delete(:keys)
17
17
  ks1 = h1.delete(:keys)
@@ -36,20 +36,40 @@ module Cevennes
36
36
  d.insert(i, [ '+', -1, nil, lnum, line ]) }
37
37
 
38
38
  s = d.inject({}) { |h, (a, _, _)| h[a] = (h[a] || 0) + 1; h }
39
- s['l0'] = h0.length - 1
40
- s['l1'] = h1.length - 1
39
+ s['l0'] = h0.length
40
+ s['l1'] = h1.length
41
41
 
42
- [ [ 'keys', ks0, ks1 ], [ 'stats', s ] ] + d
42
+ [ [ 'keys', *ks0, *ks1 ], [ 'stats', s ] ] + d
43
43
  end
44
44
 
45
45
  protected
46
46
 
47
- def hash(id, csv)
47
+ def strip(row)
48
+
49
+ row.collect { |cell| cell.is_a?(String) ? cell.strip : cell }
50
+ end
51
+
52
+ DOWNCASE_IF_POSSIBLE =
53
+ lambda { |x| x.respond_to?(:downcase) ? x.downcase : x }
54
+ IDENTITY =
55
+ lambda { |x| x }
56
+
57
+ def hash(version, id, csv, opts)
58
+
59
+ d = opts[:ignore_key_case] ? DOWNCASE_IF_POSSIBLE : IDENTITY
48
60
 
49
61
  csva = ::CSV.parse(reencode(csv))
50
- .each_with_index.collect { |row, i| [ 1 + i, row ] }
62
+ .each_with_index.collect { |row, i| [ 1 + i, strip(row) ] }
51
63
  .reject { |i, row| row.compact.empty? }
52
- .drop_while { |i, row| ! row.include?(id) }
64
+ .drop_while { |i, row| ! row.find { |cell| d[cell] == id } }
65
+
66
+ fail ::IndexError.new("id #{id.inspect} not found in #{version} CSV") \
67
+ if csva.empty?
68
+
69
+ csva[0][1] =
70
+ opts[:ignore_key_case] ?
71
+ csva[0][1].collect { |c| DOWNCASE_IF_POSSIBLE[c] } :
72
+ csva[0][1]
53
73
 
54
74
  idi = csva[0][1].index(id)
55
75
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cevennes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-03 00:00:00.000000000 Z
11
+ date: 2021-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -38,11 +38,15 @@ files:
38
38
  - README.md
39
39
  - cevennes.gemspec
40
40
  - lib/cevennes.rb
41
- homepage: http://github.com/jmettraux/cevennes
41
+ homepage: https://github.com/jmettraux/cevennes
42
42
  licenses:
43
43
  - MIT
44
44
  metadata:
45
- changelog_uri: http://github.com/jmettraux/cevennes/blob/master/CHANGELOG.md
45
+ changelog_uri: https://github.com/jmettraux/cevennes/blob/master/CHANGELOG.md
46
+ documentation_uri: https://github.com/jmettraux/cevennes
47
+ bug_tracker_uri: https://github.com/jmettraux/cevennes/issues
48
+ homepage_uri: https://github.com/jmettraux/cevennes
49
+ source_code_uri: https://github.com/jmettraux/cevennes
46
50
  post_install_message:
47
51
  rdoc_options: []
48
52
  require_paths:
@@ -58,8 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
62
  - !ruby/object:Gem::Version
59
63
  version: '0'
60
64
  requirements: []
61
- rubyforge_project:
62
- rubygems_version: 2.6.14.1
65
+ rubygems_version: 3.0.3
63
66
  signing_key:
64
67
  specification_version: 4
65
68
  summary: CSV diff library