cevennes 1.0.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: ea7e96b87743825f65f95ecda2fd3d9bae8d74a5
4
- data.tar.gz: 2ebe50c32f0889d5dcc92ecdb029feb9e390cef1
2
+ SHA256:
3
+ metadata.gz: '0885436a7e993e83fcef22afb0605648f92405916461a1fdc3d36c144c67530d'
4
+ data.tar.gz: dd03ef25ed11cea3be74301d4bc147da9108e91e477066d4790f3906e819f67b
5
5
  SHA512:
6
- metadata.gz: c52dc9eed861868b48bb28601e6c99f74b2770d95cc5263c33bc978978d9336be2418e336eed560d777016ec6a698c4887624e5c6513ad98b2843749de614a08
7
- data.tar.gz: ef83bf46e2c16a34d7dcf34da8d4edcc335eb9568356bfac0d20fb624fc8115a74692cf62bff52d7443bb51b82850a8f095b1c606e4f5701f5daafddc41b906e
6
+ metadata.gz: 9a9c66767526700a4c699fc61f3c938e8724a86dbc8662548bd611fb0b02fcddf1ec10c6e7a8acfcb24bd04659dc5eb20b3872a81f0866475d6c20a6ab1eb815
7
+ data.tar.gz: 14e19d5de67104106a904e58c4678a5243dce467e7b26388c9e95d7fd2d4ef8821ae5c4f0c8b3ba488081d8819d2919d3ec418ca523304c95a2a10d82fb7340c
data/CHANGELOG.md CHANGED
@@ -2,7 +2,12 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
- ## cevennes 1.0.0 not yet released
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
6
11
 
7
12
  - Align the "keys" entry on the =+-! entries
8
13
 
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
@@ -9,7 +9,7 @@ Diffs CSVs by lines, focusing on a single ID
9
9
 
10
10
  ## usage
11
11
 
12
- Given two CSV strings and an identifier name, cevennes may compute a diff:
12
+ Given two CSV strings and an identifier name (a column name), cevennes may compute a diff:
13
13
  ```ruby
14
14
  require 'cevennes'
15
15
 
@@ -27,6 +27,9 @@ cvs1 = %{
27
27
  }.strip + "\n"
28
28
 
29
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")
30
33
  ```
31
34
 
32
35
  `d` will yield:
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
 
data/lib/cevennes.rb CHANGED
@@ -4,14 +4,14 @@ require 'csv'
4
4
 
5
5
  module Cevennes
6
6
 
7
- VERSION = '1.0.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('old', id, csv0)
14
- h1 = hash('new', 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)
@@ -49,16 +49,28 @@ module Cevennes
49
49
  row.collect { |cell| cell.is_a?(String) ? cell.strip : cell }
50
50
  end
51
51
 
52
- def hash(version, id, csv)
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
53
60
 
54
61
  csva = ::CSV.parse(reencode(csv))
55
62
  .each_with_index.collect { |row, i| [ 1 + i, strip(row) ] }
56
63
  .reject { |i, row| row.compact.empty? }
57
- .drop_while { |i, row| ! row.include?(id) }
64
+ .drop_while { |i, row| ! row.find { |cell| d[cell] == id } }
58
65
 
59
66
  fail ::IndexError.new("id #{id.inspect} not found in #{version} CSV") \
60
67
  if csva.empty?
61
68
 
69
+ csva[0][1] =
70
+ opts[:ignore_key_case] ?
71
+ csva[0][1].collect { |c| DOWNCASE_IF_POSSIBLE[c] } :
72
+ csva[0][1]
73
+
62
74
  idi = csva[0][1].index(id)
63
75
 
64
76
  csva[1..-1]
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: 1.0.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-07 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,15 +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
46
- documentation_uri: http://github.com/jmettraux/cevennes
47
- bug_tracker_uri: http://github.com/jmettraux/cevennes/issues
48
- homepage_uri: http://github.com/jmettraux/cevennes
49
- source_code_uri: http://github.com/jmettraux/cevennes
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
50
50
  post_install_message:
51
51
  rdoc_options: []
52
52
  require_paths:
@@ -62,8 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  requirements: []
65
- rubyforge_project:
66
- rubygems_version: 2.6.14.1
65
+ rubygems_version: 3.0.3
67
66
  signing_key:
68
67
  specification_version: 4
69
68
  summary: CSV diff library