csv-utils 0.3.9 → 0.3.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/csv-utils.gemspec +1 -1
- data/lib/csv_utils/csv_iterator.rb +22 -1
- data/lib/csv_utils/csv_sort.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b2f52d8b1cfd29d0c74a0349bb889e1372da49c4d37986c38ff779d117a0eff
|
4
|
+
data.tar.gz: e67601c2eaf28e60e2d1dbc55ade05ddacb79a7ad350ff4c4667a0dbce6e046f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6e5eb939a6c4a67977522dcbc7cfeb5c456cb2b890c046cf1adca7a6747eebc5fb534b9ba239e58e6c1fc74e90302f021bfcc34e8b5db6259dda8de98db9bbb
|
7
|
+
data.tar.gz: f5005436ad1f3f92f6f9c8aa350a2063779d15fbd4e86db9b3eb3aeb971efe5949798ef7853f6baed125f06e0fec9356ad0bce1a5087f3ffb84db82a49dfffae
|
data/csv-utils.gemspec
CHANGED
@@ -14,7 +14,7 @@ class CSVUtils::CSVIterator
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_pretty_s
|
17
|
-
reject { |_, v| v.strip.empty? }
|
17
|
+
reject { |_, v| v.nil? || v.strip.empty? }
|
18
18
|
.each_with_index
|
19
19
|
.map { |(k, v), idx| sprintf(' %-3d %s: %s', idx+1, k, v) }
|
20
20
|
.join("\n") + "\n"
|
@@ -43,6 +43,27 @@ class CSVUtils::CSVIterator
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
def headers
|
47
|
+
@src_csv.rewind
|
48
|
+
@src_csv.shift
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_hash(key, value = nil)
|
52
|
+
raise("header #{key} not found in #{headers}") unless headers.include?(key)
|
53
|
+
raise("headers #{value} not found in #{headers}") if value && !headers.include?(value)
|
54
|
+
|
55
|
+
value_proc =
|
56
|
+
if value
|
57
|
+
proc { |row| row[value] }
|
58
|
+
else
|
59
|
+
proc { |row| yield(row) }
|
60
|
+
end
|
61
|
+
|
62
|
+
each_with_object({}) do |row, hsh|
|
63
|
+
hsh[row[key]] = value_proc.call(row)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
46
67
|
private
|
47
68
|
|
48
69
|
def strip_bom!(col)
|
data/lib/csv_utils/csv_sort.rb
CHANGED
@@ -107,6 +107,10 @@ class CSVUtils::CSVSort
|
|
107
107
|
File.unlink(csv_part_file2)
|
108
108
|
end
|
109
109
|
|
110
|
-
|
110
|
+
if @csv_part_files.size > 0
|
111
|
+
FileUtils.mv(@csv_part_files.last, new_csv_file)
|
112
|
+
else
|
113
|
+
FileUtils.cp(@csv_file, new_csv_file)
|
114
|
+
end
|
111
115
|
end
|
112
116
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug Youch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inheritance-helper
|