cevennes 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +7 -0
  4. data/lib/cevennes.rb +20 -15
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fb788c6c511d207dbeb25a03ffb061da5485de2
4
- data.tar.gz: 9a20b7faae773a410f8c04d919810099529f664d
3
+ metadata.gz: e8fcfbf02c5a728c9a6364a0fe67a61003fa18fa
4
+ data.tar.gz: 72361059d05b8c7cca589fa099d4e92a58ca704d
5
5
  SHA512:
6
- metadata.gz: 33684d80bfff9bab6755492edf1e97f09928d992619f5af5704e962c2f1a160ac110d7f587386b3ad2a5b9a3402247ef9ec11b1a65170c74ba7b016f7933ff1e
7
- data.tar.gz: c348f6108095abe5c00201ff3ac39948d607cdc7e5f222af64fe4e9f841734625f1a79f31524ba23bd68f7a04cc7b7ebe92f3cf0b758ef385b02d241d6f3dad4
6
+ metadata.gz: fd04c1d5c12954d091a75b55ccb0078757a35bfc1d7d7dc6fcf2cf3d23ecb6929ec47d05adbfc13be1646a4ca6040a05135b9ce4664a5f5947b5413e01bf4fd0
7
+ data.tar.gz: ee72cda27967a186dfea52a61ef67256b69f3d56ec95c0c3d0e61bc1084a74a35a59e3025a8a5666e29e7ebfc649c8c6d48a16dda7a64bc4919fbeee255252ee
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## cevennes 0.10.0 released 2018-09-03
6
+
7
+ - Weave in additions at the right spot
8
+ - Indicate line numbers
9
+
10
+
5
11
  ## cevennes 0.9.0 released 2018-09-03
6
12
 
7
13
  - Implement first version of Cevennes.diff(id, cvs0, cvs1)
data/README.md CHANGED
@@ -9,6 +9,13 @@ Diffs CSVs by lines, focusing on a single ID
9
9
  ## usage
10
10
 
11
11
  TODO
12
+ ```
13
+ csv0 = %{
14
+ }
15
+ csv1 = %{
16
+ }
17
+ pp Cevennes.diff('ISIN', csv0, csv1)
18
+ ```
12
19
 
13
20
  ## LICENSE
14
21
 
data/lib/cevennes.rb CHANGED
@@ -4,7 +4,7 @@ require 'csv'
4
4
 
5
5
  module Cevennes
6
6
 
7
- VERSION = '0.9.0'
7
+ VERSION = '0.10.0'
8
8
 
9
9
  class << self
10
10
 
@@ -20,16 +20,20 @@ module Cevennes
20
20
  h0
21
21
  .collect { |k, v|
22
22
  v1 = h1[k]
23
- if v1 == v
24
- [ '=', v, nil ]
23
+ if v1 == nil
24
+ [ '-', *v, -1, nil ]
25
+ elsif v1[1] == v[1]
26
+ [ '=', *v, v[0], nil ]
25
27
  else
26
- [ v1 == nil ? '-' : '!', v, v1 ]
28
+ [ '!', *v, *v1 ]
27
29
  end }
28
- .compact +
29
- (h1.keys - h0.keys)
30
- .collect { |k|
31
- v = h1[k]
32
- [ '+', nil, h1[k] ] }
30
+
31
+ (h1.keys - h0.keys)
32
+ .collect { |k| h1[k] }
33
+ .reverse
34
+ .each { |lnum, line|
35
+ i = d.index { |a, _, _, l1, _| l1 > lnum } || d.length
36
+ d.insert(i, [ '+', -1, nil, lnum, line ]) }
33
37
 
34
38
  s = d.inject({}) { |h, (a, _, _)| h[a] = (h[a] || 0) + 1; h }
35
39
  s['l0'] = h0.length - 1
@@ -43,16 +47,17 @@ module Cevennes
43
47
  def hash(id, csv)
44
48
 
45
49
  csva = ::CSV.parse(reencode(csv))
46
- .reject { |row| row.compact.empty? }
47
- .drop_while { |row| ! row.include?(id) }
50
+ .each_with_index.collect { |row, i| [ 1 + i, row ] }
51
+ .reject { |i, row| row.compact.empty? }
52
+ .drop_while { |i, row| ! row.include?(id) }
48
53
 
49
- i = csva[0].index(id)
54
+ idi = csva[0][1].index(id)
50
55
 
51
56
  csva[1..-1]
52
- .inject({ keys: csva[0] }) { |h, row|
57
+ .inject({ keys: csva[0] }) { |h, (i, row)|
53
58
  if row.compact.length > 1
54
- k = row[i]
55
- h[k] = row if k
59
+ k = row[idi]
60
+ h[k] = [ i, row ] if k
56
61
  end
57
62
  h }
58
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cevennes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux