enum_csv 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -5
- data/lib/enum_csv.rb +18 -27
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ce120d324f6b9eb467778d32de89939bcd8f02f02d364e74eeb88ee8e4de9f4
|
4
|
+
data.tar.gz: fd62bf611e86e4b2e2e26b0b3450e83292445b12ae2a42f6a493dcd71c6f1dee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9236d20fa145e6ebe6917fe5be47c681397a5e502e9757ae4441032dbef8551ced99a4bc5b22d1c484b086fcdffea18125ba95d0e6bd9552d211b99eff6b868a
|
7
|
+
data.tar.gz: 54c1d55ae3de6ca4d4208113c319bcabbb76c0e8dc746f9a1b2e0ce7c4395979283607c410900a56874950d76888692c4bb784e750d26a346e34042d2dad2db2
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== 1.2.0 (2023-09-19)
|
2
|
+
|
3
|
+
* Set required_ruby_version to 2.3+, as no version of the csv gem supports Ruby <2.3 (jeremyevans)
|
4
|
+
|
5
|
+
* Add dependency on csv, as csv is moving from standard library to bundled gem in Ruby 3.4 (jeremyevans)
|
6
|
+
|
1
7
|
=== 1.1.1 (2020-01-31)
|
2
8
|
|
3
9
|
* Drop shipping of tests in gem (jeremyevans)
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= EnumCSV
|
2
2
|
|
3
3
|
EnumCSV exposes a single method, csv, for easily creating CSV
|
4
|
-
output/files from enumerable objects. It is a
|
4
|
+
output/files from enumerable objects. It is a simple wrapper
|
5
5
|
class for ruby's csv library.
|
6
6
|
|
7
7
|
= Installation
|
@@ -34,10 +34,6 @@ output:
|
|
34
34
|
|
35
35
|
EnumCSV.csv([{:a=>1, :b=>2}, {:a=>3, :b=>4}]){|l| [l[:b], l[:a] + 10]} => "2,11\n4,13\n"
|
36
36
|
|
37
|
-
= Ruby 1.8 Usage
|
38
|
-
|
39
|
-
On Ruby 1.8, you need to install the fastercsv gem to use this library.
|
40
|
-
|
41
37
|
= License
|
42
38
|
|
43
39
|
MIT
|
data/lib/enum_csv.rb
CHANGED
@@ -1,26 +1,10 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
|
1
5
|
# EnumCSV exposes a single method, csv, for easily creating CSV
|
2
6
|
# output/files from enumerable objects.
|
3
7
|
module EnumCSV
|
4
|
-
if RUBY_VERSION >= '1.9'
|
5
|
-
require 'csv'
|
6
|
-
else
|
7
|
-
require 'fastercsv'
|
8
|
-
# Use FasterCSV on ruby 1.8
|
9
|
-
CSV = ::FasterCSV
|
10
|
-
end
|
11
|
-
|
12
|
-
if RUBY_VERSION >= "2.0"
|
13
|
-
instance_eval(<<-END, __FILE__, __LINE__+1)
|
14
|
-
def self.csv_call(*args, opts, &block)
|
15
|
-
CSV.send(*args, **opts, &block)
|
16
|
-
end
|
17
|
-
END
|
18
|
-
else
|
19
|
-
def self.csv_call(*args, &block)
|
20
|
-
CSV.send(*args, &block)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
8
|
# Create CSV from the given Enumerable object. If a block is given,
|
25
9
|
# each item in the enumerable is yielded to the block, and the block
|
26
10
|
# should return an array of of items to use for the CSV line.
|
@@ -35,8 +19,17 @@ module EnumCSV
|
|
35
19
|
def csv(enum, opts={})
|
36
20
|
headers = opts[:headers]
|
37
21
|
headers = headers.split(',') if headers.is_a?(String)
|
38
|
-
|
39
|
-
|
22
|
+
has_headers = headers.is_a?(Array) && !opts.has_key?(:write_headers)
|
23
|
+
has_file = opts[:file]
|
24
|
+
|
25
|
+
if has_headers || has_file
|
26
|
+
opts = opts.dup
|
27
|
+
file = opts.delete(:file)
|
28
|
+
|
29
|
+
if has_headers
|
30
|
+
opts[:write_headers] = true
|
31
|
+
opts[:headers] = headers
|
32
|
+
end
|
40
33
|
end
|
41
34
|
|
42
35
|
csv_proc = proc do |csv|
|
@@ -46,13 +39,11 @@ module EnumCSV
|
|
46
39
|
end
|
47
40
|
end
|
48
41
|
|
49
|
-
if
|
50
|
-
|
51
|
-
file = opts.delete(:file)
|
52
|
-
EnumCSV.csv_call(:open, file, 'wb', opts, &csv_proc)
|
42
|
+
if file
|
43
|
+
CSV.open(file, 'wb', **opts, &csv_proc)
|
53
44
|
nil
|
54
45
|
else
|
55
|
-
|
46
|
+
CSV.generate(**opts, &csv_proc)
|
56
47
|
end
|
57
48
|
end
|
58
49
|
module_function :csv
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enum_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: csv
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: minitest
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,7 +74,7 @@ metadata:
|
|
60
74
|
bug_tracker_uri: https://github.com/jeremyevans/enum_csv/issues
|
61
75
|
changelog_uri: https://github.com/jeremyevans/enum_csv/blob/master/CHANGELOG
|
62
76
|
source_code_uri: https://github.com/jeremyevans/enum_csv
|
63
|
-
post_install_message:
|
77
|
+
post_install_message:
|
64
78
|
rdoc_options:
|
65
79
|
- "--quiet"
|
66
80
|
- "--line-numbers"
|
@@ -75,15 +89,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
89
|
requirements:
|
76
90
|
- - ">="
|
77
91
|
- !ruby/object:Gem::Version
|
78
|
-
version: '
|
92
|
+
version: '2.3'
|
79
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
94
|
requirements:
|
81
95
|
- - ">="
|
82
96
|
- !ruby/object:Gem::Version
|
83
97
|
version: '0'
|
84
98
|
requirements: []
|
85
|
-
rubygems_version: 3.
|
86
|
-
signing_key:
|
99
|
+
rubygems_version: 3.4.10
|
100
|
+
signing_key:
|
87
101
|
specification_version: 4
|
88
102
|
summary: Create CSV from Enumerables
|
89
103
|
test_files: []
|