enum_csv 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9ca3cb725d6f4a47be3ac7145ee80bdbe420c1d4
4
- data.tar.gz: b28cc4f0c6c523df4c71d2237ea668c183729f73
2
+ SHA256:
3
+ metadata.gz: 5ce120d324f6b9eb467778d32de89939bcd8f02f02d364e74eeb88ee8e4de9f4
4
+ data.tar.gz: fd62bf611e86e4b2e2e26b0b3450e83292445b12ae2a42f6a493dcd71c6f1dee
5
5
  SHA512:
6
- metadata.gz: 3f56f71c6eadcb3278d353b092d504a60b7bb83dce0a123598ca3559e22927c4e48d4ceb56acf12488a7916fc0b8713a6bed2f03357d877ad61554e3b832aa45
7
- data.tar.gz: 31e4c7948415934ed139d0bf655948900be85baf6fb2eabb49495cfc7fb301e502807d22e214132b01ab876d2fc524abfd00f3a714752682a753f948ef41de46
6
+ metadata.gz: 9236d20fa145e6ebe6917fe5be47c681397a5e502e9757ae4441032dbef8551ced99a4bc5b22d1c484b086fcdffea18125ba95d0e6bd9552d211b99eff6b868a
7
+ data.tar.gz: 54c1d55ae3de6ca4d4208113c319bcabbb76c0e8dc746f9a1b2e0ce7c4395979283607c410900a56874950d76888692c4bb784e750d26a346e34042d2dad2db2
data/CHANGELOG CHANGED
@@ -1,3 +1,15 @@
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
+
7
+ === 1.1.1 (2020-01-31)
8
+
9
+ * Drop shipping of tests in gem (jeremyevans)
10
+
11
+ * Avoid keyword argument separation warnings on Ruby 2.7+ (jeremyevans)
12
+
1
13
  === 1.1.0 (2015-01-27)
2
14
 
3
15
  * Support a comma-delimited string for the :headers option (jeremyevans)
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Jeremy Evans
1
+ Copyright (c) 2013-2023 Jeremy Evans
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to
data/README.rdoc CHANGED
@@ -1,12 +1,12 @@
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 super simple wrapper
4
+ output/files from enumerable objects. It is a simple wrapper
5
5
  class for ruby's csv library.
6
6
 
7
7
  = Installation
8
8
 
9
- sudo gem install enum_csv
9
+ gem install enum_csv
10
10
 
11
11
  = Source Code
12
12
 
@@ -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,14 +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
8
  # Create CSV from the given Enumerable object. If a block is given,
13
9
  # each item in the enumerable is yielded to the block, and the block
14
10
  # should return an array of of items to use for the CSV line.
@@ -23,8 +19,17 @@ module EnumCSV
23
19
  def csv(enum, opts={})
24
20
  headers = opts[:headers]
25
21
  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)
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
28
33
  end
29
34
 
30
35
  csv_proc = proc do |csv|
@@ -34,13 +39,11 @@ module EnumCSV
34
39
  end
35
40
  end
36
41
 
37
- if opts[:file]
38
- opts = opts.dup
39
- file = opts.delete(:file)
40
- CSV.open(file, 'wb', opts, &csv_proc)
42
+ if file
43
+ CSV.open(file, 'wb', **opts, &csv_proc)
41
44
  nil
42
45
  else
43
- CSV.generate(opts, &csv_proc)
46
+ CSV.generate(**opts, &csv_proc)
44
47
  end
45
48
  end
46
49
  module_function :csv
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enum_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
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: 2015-01-27 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-09-19 00:00:00.000000000 Z
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-global_expectations
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
13
55
  description: |
14
56
  EnumCSV exposes a single method, csv, for easily creating CSV
15
57
  output/files from enumerable objects.
@@ -24,14 +66,15 @@ files:
24
66
  - CHANGELOG
25
67
  - MIT-LICENSE
26
68
  - README.rdoc
27
- - Rakefile
28
69
  - lib/enum_csv.rb
29
- - spec/enum_csv_spec.rb
30
70
  homepage: http://github.com/jeremyevans/enum_csv
31
71
  licenses:
32
72
  - MIT
33
- metadata: {}
34
- post_install_message:
73
+ metadata:
74
+ bug_tracker_uri: https://github.com/jeremyevans/enum_csv/issues
75
+ changelog_uri: https://github.com/jeremyevans/enum_csv/blob/master/CHANGELOG
76
+ source_code_uri: https://github.com/jeremyevans/enum_csv
77
+ post_install_message:
35
78
  rdoc_options:
36
79
  - "--quiet"
37
80
  - "--line-numbers"
@@ -46,16 +89,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
46
89
  requirements:
47
90
  - - ">="
48
91
  - !ruby/object:Gem::Version
49
- version: '0'
92
+ version: '2.3'
50
93
  required_rubygems_version: !ruby/object:Gem::Requirement
51
94
  requirements:
52
95
  - - ">="
53
96
  - !ruby/object:Gem::Version
54
97
  version: '0'
55
98
  requirements: []
56
- rubyforge_project:
57
- rubygems_version: 2.4.5
58
- signing_key:
99
+ rubygems_version: 3.4.10
100
+ signing_key:
59
101
  specification_version: 4
60
102
  summary: Create CSV from Enumerables
61
103
  test_files: []
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
-
@@ -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