cevennes 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/lib/cevennes.rb +20 -13
  4. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0885436a7e993e83fcef22afb0605648f92405916461a1fdc3d36c144c67530d'
4
- data.tar.gz: dd03ef25ed11cea3be74301d4bc147da9108e91e477066d4790f3906e819f67b
3
+ metadata.gz: f6b604ac611ad1d24fe34ce9769c5d5b34ca1f0cdbf005ff08bce1152f24976e
4
+ data.tar.gz: e2925852747049479ad3172780c62e1c32ec9d04958d6de7c82049a7aa8103ae
5
5
  SHA512:
6
- metadata.gz: 9a9c66767526700a4c699fc61f3c938e8724a86dbc8662548bd611fb0b02fcddf1ec10c6e7a8acfcb24bd04659dc5eb20b3872a81f0866475d6c20a6ab1eb815
7
- data.tar.gz: 14e19d5de67104106a904e58c4678a5243dce467e7b26388c9e95d7fd2d4ef8821ae5c4f0c8b3ba488081d8819d2919d3ec418ca523304c95a2a10d82fb7340c
6
+ metadata.gz: 7f77f3878e80646e0ea1d0b2c67bd6927cd5c60ab7b08acdb78747c83e14c6c38752753d4a90f055fdfc797a72f675dbe069240b278110f7b402dc2992d88c42
7
+ data.tar.gz: b6ad6a2ab702e874bc03a6ca11c265fcd3157f77a556482a447e8d579381be5a50812e23ff1b6253032a50f9a5347af1ef849f5a37128ce7c20cc6c5d5c23e78
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## cevennes 1.1.1 released 2021-02-25
6
+
7
+ - Refine UTF-8 re-encoding
8
+ - Fix `ignore_key_case: true` :-(
9
+ - Clarify reencode
10
+
11
+
5
12
  ## cevennes 1.1.0 released 2021-02-24
6
13
 
7
14
  - Introduce `ignore_key_case: true`
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.1.0'
8
+ VERSION = '1.1.1'
8
9
 
9
10
  class << self
10
11
 
@@ -49,29 +50,28 @@ module Cevennes
49
50
  row.collect { |cell| cell.is_a?(String) ? cell.strip : cell }
50
51
  end
51
52
 
52
- DOWNCASE_IF_POSSIBLE =
53
- lambda { |x| x.respond_to?(:downcase) ? x.downcase : x }
54
- IDENTITY =
55
- lambda { |x| x }
53
+ DOWNCASE = lambda { |x| x.respond_to?(:downcase) ? x.downcase : x }
54
+ IDENTITY = lambda { |x| x }
56
55
 
57
56
  def hash(version, id, csv, opts)
58
57
 
59
- d = opts[:ignore_key_case] ? DOWNCASE_IF_POSSIBLE : IDENTITY
58
+ d = opts[:ignore_key_case] ? DOWNCASE : IDENTITY
59
+ did = d[id]
60
60
 
61
61
  csva = ::CSV.parse(reencode(csv))
62
62
  .each_with_index.collect { |row, i| [ 1 + i, strip(row) ] }
63
63
  .reject { |i, row| row.compact.empty? }
64
- .drop_while { |i, row| ! row.find { |cell| d[cell] == id } }
64
+ .drop_while { |i, row| ! row.find { |cell| d[cell] == did } }
65
65
 
66
66
  fail ::IndexError.new("id #{id.inspect} not found in #{version} CSV") \
67
67
  if csva.empty?
68
68
 
69
69
  csva[0][1] =
70
70
  opts[:ignore_key_case] ?
71
- csva[0][1].collect { |c| DOWNCASE_IF_POSSIBLE[c] } :
71
+ csva[0][1].collect { |c| DOWNCASE[c] } :
72
72
  csva[0][1]
73
73
 
74
- idi = csva[0][1].index(id)
74
+ idi = csva[0][1].index(did)
75
75
 
76
76
  csva[1..-1]
77
77
  .inject({ keys: csva[0] }) { |h, (i, row)|
@@ -86,16 +86,23 @@ module Cevennes
86
86
  # ::CSV.generate(encoding: 'UTF-8') { |csv| csv << row }.strip
87
87
  #end
88
88
 
89
+ ENCODINGS = %w[ Windows-1252 ISO-8859-1 UTF-8 ].freeze
90
+
89
91
  def reencode(s)
90
92
 
91
93
  #s = unzip(s) if s[0, 2] == 'PK'
92
94
  # no dependency on rubyzip
93
95
 
94
- %w[ Windows-1252 ISO-8859-1 UTF-8 ].each do |e|
95
- ss = s.force_encoding(e).encode('UTF-8') rescue nil
96
- break ss if ss
97
- nil
96
+ #return s if s.encoding == Encoding::UTF_8
97
+ # NO! have to force_encoding for UTF-8 as well!
98
+
99
+ s = s.dup if s.frozen?
100
+
101
+ ENCODINGS.each do |e|
102
+ (return s.force_encoding(e).encode('UTF-8')) rescue nil
98
103
  end
104
+
105
+ nil
99
106
  end
100
107
  end
101
108
  end
metadata CHANGED
@@ -1,22 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cevennes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
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: 2021-02-24 00:00:00.000000000 Z
11
+ date: 2021-02-25 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'
19
+ name: rspec
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -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.0.3
66
- signing_key:
65
+ rubygems_version: 3.0.6
66
+ signing_key:
67
67
  specification_version: 4
68
68
  summary: CSV diff library
69
69
  test_files: []