enum_csv 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG +6 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/enum_csv.rb +14 -2
- metadata +36 -8
- data/Rakefile +0 -69
- data/spec/enum_csv_spec.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bf6594ec66acf55668a9d70fcfaf595f6ddd157022acaa7894a3e735f4f5305d
|
4
|
+
data.tar.gz: bbb9893a0c9d14a3967f01ba35cedbe9e42bbea514b426f26709b707ffe3cbcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b358bcb72dd5da340d8c253a0cdd97020249272c43bcc71bd846ebe422f4a43889fa8b456237bcbea8597559acc74dbd1a42724d74a15638ca427faf6b2e444f
|
7
|
+
data.tar.gz: d247c0c3ca1c2c8c61ec436ed19c58e21d3da466e7c478434e956db4352905da754dce2ebc14c7a6c3c96dab4c39ebd6391f9d7d14ef30717e54d3a459a0b3e4
|
data/CHANGELOG
CHANGED
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
data/lib/enum_csv.rb
CHANGED
@@ -9,6 +9,18 @@ module EnumCSV
|
|
9
9
|
CSV = ::FasterCSV
|
10
10
|
end
|
11
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
|
+
|
12
24
|
# Create CSV from the given Enumerable object. If a block is given,
|
13
25
|
# each item in the enumerable is yielded to the block, and the block
|
14
26
|
# should return an array of of items to use for the CSV line.
|
@@ -37,10 +49,10 @@ module EnumCSV
|
|
37
49
|
if opts[:file]
|
38
50
|
opts = opts.dup
|
39
51
|
file = opts.delete(:file)
|
40
|
-
|
52
|
+
EnumCSV.csv_call(:open, file, 'wb', opts, &csv_proc)
|
41
53
|
nil
|
42
54
|
else
|
43
|
-
|
55
|
+
EnumCSV.csv_call(:generate, opts, &csv_proc)
|
44
56
|
end
|
45
57
|
end
|
46
58
|
module_function :csv
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enum_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2020-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest-global_expectations
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description: |
|
14
42
|
EnumCSV exposes a single method, csv, for easily creating CSV
|
15
43
|
output/files from enumerable objects.
|
@@ -24,13 +52,14 @@ files:
|
|
24
52
|
- CHANGELOG
|
25
53
|
- MIT-LICENSE
|
26
54
|
- README.rdoc
|
27
|
-
- Rakefile
|
28
55
|
- lib/enum_csv.rb
|
29
|
-
- spec/enum_csv_spec.rb
|
30
56
|
homepage: http://github.com/jeremyevans/enum_csv
|
31
57
|
licenses:
|
32
58
|
- MIT
|
33
|
-
metadata:
|
59
|
+
metadata:
|
60
|
+
bug_tracker_uri: https://github.com/jeremyevans/enum_csv/issues
|
61
|
+
changelog_uri: https://github.com/jeremyevans/enum_csv/blob/master/CHANGELOG
|
62
|
+
source_code_uri: https://github.com/jeremyevans/enum_csv
|
34
63
|
post_install_message:
|
35
64
|
rdoc_options:
|
36
65
|
- "--quiet"
|
@@ -53,8 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
82
|
- !ruby/object:Gem::Version
|
54
83
|
version: '0'
|
55
84
|
requirements: []
|
56
|
-
|
57
|
-
rubygems_version: 2.4.5
|
85
|
+
rubygems_version: 3.1.2
|
58
86
|
signing_key:
|
59
87
|
specification_version: 4
|
60
88
|
summary: Create CSV from Enumerables
|
data/Rakefile
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require "rake"
|
2
|
-
require "rake/clean"
|
3
|
-
|
4
|
-
CLEAN.include ["enum_csv-*.gem", "rdoc", "coverage"]
|
5
|
-
|
6
|
-
desc "Build enum_csv gem"
|
7
|
-
task :package=>[:clean] do |p|
|
8
|
-
sh %{#{FileUtils::RUBY} -S gem build enum_csv.gemspec}
|
9
|
-
end
|
10
|
-
|
11
|
-
### Specs
|
12
|
-
|
13
|
-
begin
|
14
|
-
begin
|
15
|
-
# RSpec 1
|
16
|
-
require "spec/rake/spectask"
|
17
|
-
spec_class = Spec::Rake::SpecTask
|
18
|
-
spec_files_meth = :spec_files=
|
19
|
-
rescue LoadError
|
20
|
-
# RSpec 2
|
21
|
-
require "rspec/core/rake_task"
|
22
|
-
spec_class = RSpec::Core::RakeTask
|
23
|
-
spec_files_meth = :pattern=
|
24
|
-
end
|
25
|
-
|
26
|
-
spec = lambda do |name, files, d|
|
27
|
-
lib_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'lib')
|
28
|
-
ENV['RUBYLIB'] ? (ENV['RUBYLIB'] += ":#{lib_dir}") : (ENV['RUBYLIB'] = lib_dir)
|
29
|
-
desc d
|
30
|
-
spec_class.new(name) do |t|
|
31
|
-
t.send(spec_files_meth, files)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
task :default => [:spec]
|
36
|
-
spec.call("spec", Dir["spec/*_spec.rb"], "Run specs")
|
37
|
-
rescue LoadError
|
38
|
-
task :default do
|
39
|
-
puts "Must install rspec to run the default task (which runs specs)"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
### RDoc
|
44
|
-
|
45
|
-
RDOC_DEFAULT_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', 'EnumCSV: Create CSV from Enumerables']
|
46
|
-
|
47
|
-
begin
|
48
|
-
gem 'rdoc', '= 3.12.2'
|
49
|
-
gem 'hanna-nouveau'
|
50
|
-
RDOC_DEFAULT_OPTS.concat(['-f', 'hanna'])
|
51
|
-
rescue Gem::LoadError
|
52
|
-
end
|
53
|
-
|
54
|
-
rdoc_task_class = begin
|
55
|
-
require "rdoc/task"
|
56
|
-
RDoc::Task
|
57
|
-
rescue LoadError
|
58
|
-
require "rake/rdoctask"
|
59
|
-
Rake::RDocTask
|
60
|
-
end
|
61
|
-
|
62
|
-
RDOC_OPTS = RDOC_DEFAULT_OPTS + ['--main', 'README.rdoc']
|
63
|
-
|
64
|
-
rdoc_task_class.new do |rdoc|
|
65
|
-
rdoc.rdoc_dir = "rdoc"
|
66
|
-
rdoc.options += RDOC_OPTS
|
67
|
-
rdoc.rdoc_files.add %w"README.rdoc CHANGELOG MIT-LICENSE lib/**/*.rb"
|
68
|
-
end
|
69
|
-
|
data/spec/enum_csv_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require File.join(File.dirname(File.expand_path(__FILE__)), '../lib/enum_csv')
|
3
|
-
|
4
|
-
describe "EnumCSV.csv" do
|
5
|
-
TEST_FILE = File.join(File.dirname(File.expand_path(__FILE__)), 'test.csv')
|
6
|
-
after(:all) do
|
7
|
-
File.delete(TEST_FILE)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should return string of CSV data for enumerable" do
|
11
|
-
EnumCSV.csv([[1, 2]]).should == "1,2\n"
|
12
|
-
EnumCSV.csv([[1, 2], [3, 4]]).should == "1,2\n3,4\n"
|
13
|
-
EnumCSV.csv([[1, '2,3'], [3, 4]]).should == "1,\"2,3\"\n3,4\n"
|
14
|
-
EnumCSV.csv([[1, nil], [3, 4]]).should == "1,\n3,4\n"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should support :headers option for a headers string" do
|
18
|
-
EnumCSV.csv([[1, 2]], :headers=>['a', 'b']).should == "a,b\n1,2\n"
|
19
|
-
EnumCSV.csv([[1, 2], [3, 4]], :headers=>['a', 'b']).should == "a,b\n1,2\n3,4\n"
|
20
|
-
EnumCSV.csv([[1, '2,3'], [3, 4]], :headers=>['a,b', 'c']).should == "\"a,b\",c\n1,\"2,3\"\n3,4\n"
|
21
|
-
EnumCSV.csv([[1, nil], [3, 4]], :headers=>['a', nil]).should == "a,\n1,\n3,4\n"
|
22
|
-
end
|
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
|
-
|
29
|
-
it "should support :file option for writing to a file" do
|
30
|
-
EnumCSV.csv([[1, 2]], :file=>TEST_FILE).should be_nil
|
31
|
-
File.read(TEST_FILE).should == "1,2\n"
|
32
|
-
EnumCSV.csv([[1, 2]], :file=>TEST_FILE, :headers=>['a', 'b'])
|
33
|
-
File.read(TEST_FILE).should == "a,b\n1,2\n"
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should support other csv options" do
|
37
|
-
EnumCSV.csv([[1, 2]], :row_sep=>'|').should == "1,2|"
|
38
|
-
EnumCSV.csv([[1, 2], [3, 4]], :col_sep=>'^').should == "1^2\n3^4\n"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should yield elements to the block if given" do
|
42
|
-
EnumCSV.csv([[1, 2]]){|l| l.map{|i| i*2}}.should == "2,4\n"
|
43
|
-
EnumCSV.csv([[1, 2]], :headers=>['a', 'b']){|l| l.map{|i| i*2}}.should == "a,b\n2,4\n"
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should be callable as a method if including the module" do
|
47
|
-
Class.new{include EnumCSV}.new.send(:csv, [[1, 2]]).should == "1,2\n"
|
48
|
-
end
|
49
|
-
end
|