enum_csv 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 +4 -4
- data/CHANGELOG +6 -0
- data/README.rdoc +2 -1
- data/Rakefile +1 -1
- data/lib/enum_csv.rb +6 -3
- data/spec/enum_csv_spec.rb +6 -0
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ca3cb725d6f4a47be3ac7145ee80bdbe420c1d4
|
4
|
+
data.tar.gz: b28cc4f0c6c523df4c71d2237ea668c183729f73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f56f71c6eadcb3278d353b092d504a60b7bb83dce0a123598ca3559e22927c4e48d4ceb56acf12488a7916fc0b8713a6bed2f03357d877ad61554e3b832aa45
|
7
|
+
data.tar.gz: 31e4c7948415934ed139d0bf655948900be85baf6fb2eabb49495cfc7fb301e502807d22e214132b01ab876d2fc524abfd00f3a714752682a753f948ef41de46
|
data/CHANGELOG
CHANGED
data/README.rdoc
CHANGED
@@ -22,6 +22,7 @@ arrays), and returns a string containing the CSV output:
|
|
22
22
|
You can use the :headers option to set custom headers:
|
23
23
|
|
24
24
|
EnumCSV.csv([[1, 2], [3,"4,5"]], :headers=>['A', 'B']) => "A,B\n1,2\n3,\"4,5\"\n"
|
25
|
+
EnumCSV.csv([[1, 2], [3,"4,5"]], :headers=>'A,B') => "A,B\n1,2\n3,\"4,5\"\n"
|
25
26
|
|
26
27
|
The :file option can be used to output to a file:
|
27
28
|
|
@@ -31,7 +32,7 @@ If a block is passed to the method, all items in the enumerable are yielded to
|
|
31
32
|
the block, and the block should return an array with the data to use in the CSV
|
32
33
|
output:
|
33
34
|
|
34
|
-
EnumCSV.csv([{:a=>1, :b=>2}, {:a=>3, b=>4}]){|
|
35
|
+
EnumCSV.csv([{:a=>1, :b=>2}, {:a=>3, :b=>4}]){|l| [l[:b], l[:a] + 10]} => "2,11\n4,13\n"
|
35
36
|
|
36
37
|
= Ruby 1.8 Usage
|
37
38
|
|
data/Rakefile
CHANGED
@@ -36,7 +36,7 @@ begin
|
|
36
36
|
spec.call("spec", Dir["spec/*_spec.rb"], "Run specs")
|
37
37
|
rescue LoadError
|
38
38
|
task :default do
|
39
|
-
puts "Must install rspec
|
39
|
+
puts "Must install rspec to run the default task (which runs specs)"
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
data/lib/enum_csv.rb
CHANGED
@@ -15,13 +15,16 @@ module EnumCSV
|
|
15
15
|
#
|
16
16
|
# Options:
|
17
17
|
# :headers :: Should be an array of headers to use as the first
|
18
|
-
# line of the CSV output
|
18
|
+
# line of the CSV output, or a comma-delimited string
|
19
|
+
# of headers.
|
19
20
|
# :file :: Output to the given file and return nil instead of
|
20
21
|
# returning a string with the CSV output.
|
21
22
|
# all other options :: Passed to CSV.open or CSV.generate
|
22
23
|
def csv(enum, opts={})
|
23
|
-
|
24
|
-
|
24
|
+
headers = opts[:headers]
|
25
|
+
headers = headers.split(',') if headers.is_a?(String)
|
26
|
+
if headers.is_a?(Array) && !opts.has_key?(:write_headers)
|
27
|
+
opts = opts.merge(:write_headers=>true, :headers=>headers)
|
25
28
|
end
|
26
29
|
|
27
30
|
csv_proc = proc do |csv|
|
data/spec/enum_csv_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require File.join(File.dirname(File.expand_path(__FILE__)), '../lib/enum_csv')
|
2
3
|
|
3
4
|
describe "EnumCSV.csv" do
|
@@ -20,6 +21,11 @@ describe "EnumCSV.csv" do
|
|
20
21
|
EnumCSV.csv([[1, nil], [3, 4]], :headers=>['a', nil]).should == "a,\n1,\n3,4\n"
|
21
22
|
end
|
22
23
|
|
24
|
+
it "should support :headers option as a comma delimited string" do
|
25
|
+
EnumCSV.csv([[1, 2]], :headers=>'a,b').should == "a,b\n1,2\n"
|
26
|
+
EnumCSV.csv([[1, 2], [3, 4]], :headers=>'a,b').should == "a,b\n1,2\n3,4\n"
|
27
|
+
end
|
28
|
+
|
23
29
|
it "should support :file option for writing to a file" do
|
24
30
|
EnumCSV.csv([[1, 2]], :file=>TEST_FILE).should be_nil
|
25
31
|
File.read(TEST_FILE).should == "1,2\n"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enum_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
EnumCSV exposes a single method, csv, for easily creating CSV
|
@@ -21,40 +21,40 @@ extra_rdoc_files:
|
|
21
21
|
- CHANGELOG
|
22
22
|
- MIT-LICENSE
|
23
23
|
files:
|
24
|
-
- MIT-LICENSE
|
25
24
|
- CHANGELOG
|
25
|
+
- MIT-LICENSE
|
26
26
|
- README.rdoc
|
27
27
|
- Rakefile
|
28
|
-
- spec/enum_csv_spec.rb
|
29
28
|
- lib/enum_csv.rb
|
30
|
-
|
29
|
+
- spec/enum_csv_spec.rb
|
30
|
+
homepage: http://github.com/jeremyevans/enum_csv
|
31
31
|
licenses:
|
32
32
|
- MIT
|
33
33
|
metadata: {}
|
34
34
|
post_install_message:
|
35
35
|
rdoc_options:
|
36
|
-
- --quiet
|
37
|
-
- --line-numbers
|
38
|
-
- --inline-source
|
39
|
-
- --title
|
36
|
+
- "--quiet"
|
37
|
+
- "--line-numbers"
|
38
|
+
- "--inline-source"
|
39
|
+
- "--title"
|
40
40
|
- 'EnumCSV: Create CSV from Enumerables'
|
41
|
-
- --main
|
41
|
+
- "--main"
|
42
42
|
- README.rdoc
|
43
43
|
require_paths:
|
44
44
|
- lib
|
45
45
|
required_ruby_version: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0'
|
50
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
56
|
rubyforge_project:
|
57
|
-
rubygems_version: 2.
|
57
|
+
rubygems_version: 2.4.5
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: Create CSV from Enumerables
|