csv_pirate 4.1.4 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/Gemfile +12 -0
- data/README.rdoc +4 -1
- data/Rakefile +26 -22
- data/VERSION.yml +3 -3
- data/csv_pirate.gemspec +26 -30
- data/lib/{ninth_bit → csv_pirate}/pirate_ship.rb +8 -8
- data/lib/csv_pirate/the_capn.rb +689 -0
- data/lib/csv_pirate/version.rb +11 -0
- data/lib/csv_pirate.rb +6 -674
- data/spec/csv_pirate_spec.rb +34 -11
- data/spec/pirate_ship_spec.rb +8 -8
- data/spec/spec_helper.rb +4 -4
- data/spec/spec_helpers/glowing_gas_ball.rb +4 -0
- data/spec/spec_helpers/star.rb +1 -1
- data/uninstall.rb +1 -0
- metadata +25 -30
- data/init.rb +0 -1
- data/rails/init.rb +0 -50
data/CHANGELOG
CHANGED
data/Gemfile
ADDED
data/README.rdoc
CHANGED
@@ -202,7 +202,7 @@ Assuming a Make (as in manufacturers of automobiles) model like this:
|
|
202
202
|
:swag => nil # Array of objects: to use to create the CSV (i.e. you've already done the query and have the results you want a CSV of)
|
203
203
|
:grub => Make # Class: on which to call the method chain in :spyglasses that will return the array of objects to be placed in :swag by CsvPirate (See description of swag above).
|
204
204
|
:spyglasses => [:all] # Array of symbols/strings: Methods that will be chained together and called on :grub in order to get the :swag records which will become the rows of the CSV.
|
205
|
-
:booty => Make.column_names # Array of symbols/strings or nested hashes of symbols/strings: Methods to call on each object in :swag. These become the columns of the CSV. The method names become the CSV column headings. Methods can be chained to dig deep (e.g. traverse several ActiveRecord associations) to get at a value for the CSV.
|
205
|
+
:booty => Make.column_names # Array of symbols/strings or nested hashes of symbols/strings: Methods to call on each object in :swag. These become the columns of the CSV. The method names become the CSV column headings. Methods can be chained to dig deep (e.g. traverse several ActiveRecord associations) to get at a value for the CSV. To call instance methods that include arguments, pass a booty element of an array such as [:method_name, arg1, arg2...].
|
206
206
|
|
207
207
|
:swab => :counter # Symbol: What kind of file counter to use to avoid overwtiting the CSV file, :counter is Integer, :timestamp is HHMMSS, :none is no file counter, increasing the liklihood of duplicate filenames on successive csv exports.
|
208
208
|
:mop => :clean # Symbol: If we DO end up writing to a preexisting file (by design or accident) should we overwrite (:clean) or append (:dirty)?
|
@@ -281,6 +281,9 @@ If you want to traverse Active Record Associations, or call a method on the retu
|
|
281
281
|
Make.walk_the_plank({:booty => [:id, :name, :to_slug, {:to_slug => :hash}]}) #will call .hash on the result of make.to_slug
|
282
282
|
Make.walk_the_plank({:booty => [:id, :name, :to_slug, {:to_slug => {:hash => :abs}}]}) #returns make.to_slug.hash.abs
|
283
283
|
|
284
|
+
If you want to build your booty using instance functions that require arguments, use an array:
|
285
|
+
Make.walk_the_plank({:booty => [:id, :name, [:value_on, Date.today]}) # will call make.value_on(Date.today)
|
286
|
+
|
284
287
|
Add whatever methods you want to the :booty array. Write new methods, and add them! Make lots of glorious CSVs full of data to impress the pointy ones in the office.
|
285
288
|
|
286
289
|
You can also use the raw CsvPirate class itself directly wherever you want.
|
data/Rakefile
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
1
4
|
require 'rake'
|
2
5
|
|
3
6
|
begin
|
@@ -10,14 +13,14 @@ It works better if you are wearing a tricorne!}
|
|
10
13
|
gemspec.email = "peter.boling@gmail.com"
|
11
14
|
gemspec.homepage = "http://github.com/pboling/csv_pirate"
|
12
15
|
gemspec.authors = ["Peter Boling"]
|
13
|
-
#gemspec.add_dependency 'fastercsv'
|
14
16
|
gemspec.files = ["README.rdoc",
|
15
17
|
"csv_pirate.gemspec",
|
16
|
-
"init.rb",
|
17
|
-
"rails/init.rb",
|
18
18
|
"install.rb",
|
19
|
+
"uninstall.rb",
|
19
20
|
"lib/csv_pirate.rb",
|
20
|
-
"lib/
|
21
|
+
"lib/csv_pirate/pirate_ship.rb",
|
22
|
+
"lib/csv_pirate/the_capn.rb",
|
23
|
+
"lib/csv_pirate/version.rb",
|
21
24
|
"spec/csv_pirate_spec.rb",
|
22
25
|
"spec/pirate_ship_spec.rb",
|
23
26
|
"spec/spec.opts",
|
@@ -25,6 +28,7 @@ It works better if you are wearing a tricorne!}
|
|
25
28
|
"spec/spec_helpers/glowing_gas_ball.rb",
|
26
29
|
"spec/spec_helpers/star.rb",
|
27
30
|
"Rakefile",
|
31
|
+
"Gemfile",
|
28
32
|
"LICENSE",
|
29
33
|
"CHANGELOG",
|
30
34
|
"VERSION.yml"]
|
@@ -43,23 +47,23 @@ Rake::RDocTask.new do |rdoc|
|
|
43
47
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
48
|
end
|
45
49
|
|
46
|
-
require 'spec/rake/spectask'
|
47
|
-
Spec::Rake::SpecTask.new(:spec) do |t|
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
Spec::Rake::SpecTask.new(:rcov) do |t|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
begin
|
59
|
-
require 'cucumber/rake/task'
|
60
|
-
Cucumber::Rake::Task.new(:features)
|
61
|
-
rescue LoadError
|
62
|
-
puts "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
63
|
-
end
|
50
|
+
# require 'spec/rake/spectask'
|
51
|
+
# Spec::Rake::SpecTask.new(:spec) do |t|
|
52
|
+
# t.libs << 'lib' << 'spec'
|
53
|
+
# t.spec_files = FileList['spec/**/*_spec.rb']
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# Spec::Rake::SpecTask.new(:rcov) do |t|
|
57
|
+
# t.libs << 'lib' << 'spec'
|
58
|
+
# t.spec_files = FileList['spec/**/*_spec.rb']
|
59
|
+
# t.rcov = true
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
#begin
|
63
|
+
# require 'cucumber/rake/task'
|
64
|
+
# Cucumber::Rake::Task.new(:features)
|
65
|
+
#rescue LoadError
|
66
|
+
# puts "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
67
|
+
#end
|
64
68
|
|
65
69
|
task :default => :spec
|
data/VERSION.yml
CHANGED
data/csv_pirate.gemspec
CHANGED
@@ -1,62 +1,58 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{csv_pirate}
|
8
|
-
s.version = "
|
8
|
+
s.version = "5.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Peter Boling"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-06-14}
|
13
13
|
s.description = %q{CsvPirate is the easy way to create a CSV of essentially anything in Ruby, in full pirate regalia.
|
14
14
|
It works better if you are wearing a tricorne!}
|
15
15
|
s.email = %q{peter.boling@gmail.com}
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE",
|
18
|
-
|
18
|
+
"README.rdoc"
|
19
19
|
]
|
20
20
|
s.files = [
|
21
21
|
"CHANGELOG",
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
22
|
+
"Gemfile",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION.yml",
|
27
|
+
"csv_pirate.gemspec",
|
28
|
+
"install.rb",
|
29
|
+
"lib/csv_pirate.rb",
|
30
|
+
"lib/csv_pirate/pirate_ship.rb",
|
31
|
+
"lib/csv_pirate/the_capn.rb",
|
32
|
+
"lib/csv_pirate/version.rb",
|
33
|
+
"spec/csv_pirate_spec.rb",
|
34
|
+
"spec/pirate_ship_spec.rb",
|
35
|
+
"spec/spec.opts",
|
36
|
+
"spec/spec_helper.rb",
|
37
|
+
"spec/spec_helpers/glowing_gas_ball.rb",
|
38
|
+
"spec/spec_helpers/star.rb",
|
39
|
+
"uninstall.rb"
|
38
40
|
]
|
39
41
|
s.homepage = %q{http://github.com/pboling/csv_pirate}
|
40
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
41
42
|
s.require_paths = ["lib"]
|
42
|
-
s.rubygems_version = %q{1.
|
43
|
+
s.rubygems_version = %q{1.7.2}
|
43
44
|
s.summary = %q{Easily create CSVs of any data that can be derived from instance methods on your classes.}
|
44
|
-
s.test_files = [
|
45
|
-
"spec/csv_pirate_spec.rb",
|
46
|
-
"spec/pirate_ship_spec.rb",
|
47
|
-
"spec/spec_helper.rb",
|
48
|
-
"spec/spec_helpers/glowing_gas_ball.rb",
|
49
|
-
"spec/spec_helpers/star.rb"
|
50
|
-
]
|
51
45
|
|
52
46
|
if s.respond_to? :specification_version then
|
53
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
54
47
|
s.specification_version = 3
|
55
48
|
|
56
49
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<csv_pirate>, [">= 0"])
|
57
51
|
else
|
52
|
+
s.add_dependency(%q<csv_pirate>, [">= 0"])
|
58
53
|
end
|
59
54
|
else
|
55
|
+
s.add_dependency(%q<csv_pirate>, [">= 0"])
|
60
56
|
end
|
61
57
|
end
|
62
58
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module CsvPirate
|
2
2
|
module PirateShip
|
3
3
|
|
4
4
|
module ActMethods
|
@@ -29,8 +29,8 @@ module NinthBit
|
|
29
29
|
raise ArgumentError, "must provide either :swag or :grub, not both" if !options[:swag].nil? && !options[:grub].nil?
|
30
30
|
# if they provide neither
|
31
31
|
raise ArgumentError, "must provide either :swag or :grub" if options[:swag].nil? && options[:grub].nil?
|
32
|
-
raise ArgumentError, ":swab is #{options[:swab].inspect}, but must be one of #{
|
33
|
-
raise ArgumentError, ":mop is #{options[:mop].inspect}, but must be one of #{
|
32
|
+
raise ArgumentError, ":swab is #{options[:swab].inspect}, but must be one of #{TheCapn::BOOKIE.inspect}" unless TheCapn::BOOKIE.include?(options[:swab])
|
33
|
+
raise ArgumentError, ":mop is #{options[:mop].inspect}, but must be one of #{TheCapn::MOP_HEADS.inspect}" unless TheCapn::MOP_HEADS.include?(options[:mop])
|
34
34
|
raise ArgumentError, ":gibbet is #{options[:gibbet].inspect}, and does not contain a '.' character, which is required when using iterative filenames (set :swab => :none to turn off iterative filenames)" if options[:swab] != :none && (options[:gibbet].nil? || !options[:gibbet].include?('.'))
|
35
35
|
raise ArgumentError, ":waggoner is #{options[:waggoner].inspect}, and must be a string at least one character long" if options[:waggoner].nil? || options[:waggoner].length < 1
|
36
36
|
raise ArgumentError, ":booty is #{options[:booty].inspect}, and must be an array of methods to call on a class for CSV data" if check_booty && (options[:booty].nil? || !options[:booty].is_a?(Array) || options[:booty].empty?)
|
@@ -96,7 +96,7 @@ module NinthBit
|
|
96
96
|
# :type => 'text/csv; charset=iso-8859-1; header=present',
|
97
97
|
# :disposition => "attachment; filename=#{csv_pirate.nocturnal}"
|
98
98
|
def blindfold(args = {})
|
99
|
-
|
99
|
+
TheCapn.create(self.piratey_args(args))
|
100
100
|
end
|
101
101
|
|
102
102
|
# returns the csv_pirate object so you have access to everything
|
@@ -106,7 +106,7 @@ module NinthBit
|
|
106
106
|
# csv_pirate.booty -= [:id, :name]
|
107
107
|
# csv_pirate.hoist_mainstay()
|
108
108
|
def land_ho(args = {})
|
109
|
-
|
109
|
+
TheCapn.new(self.piratey_args(args))
|
110
110
|
end
|
111
111
|
|
112
112
|
def weigh_anchor(args = {})
|
@@ -115,7 +115,7 @@ module NinthBit
|
|
115
115
|
:gibbet => '.dump',
|
116
116
|
:chart => pargs[:chart] + ["dumps"],
|
117
117
|
})
|
118
|
-
|
118
|
+
TheCapn.create(pargs)
|
119
119
|
end
|
120
120
|
|
121
121
|
def raise_anchor(permanence = {:new => :new}, args = {})
|
@@ -124,7 +124,7 @@ module NinthBit
|
|
124
124
|
:chart => pargs[:chart] + ["dumps"],
|
125
125
|
:brigantine => :last
|
126
126
|
})
|
127
|
-
csv_pirate =
|
127
|
+
csv_pirate = TheCapn.new(pargs)
|
128
128
|
|
129
129
|
csv_pirate.to_memory(permanence)
|
130
130
|
end
|
@@ -132,7 +132,7 @@ module NinthBit
|
|
132
132
|
protected
|
133
133
|
|
134
134
|
def piratey_args(args = {})
|
135
|
-
|
135
|
+
TheCapn.parlay ||= args[:parlay] || self.piratey_options[:parlay]
|
136
136
|
return { :chart => args[:chart] || self.piratey_options[:chart],
|
137
137
|
:aft => args[:aft] || self.piratey_options[:aft],
|
138
138
|
:gibbet => args[:gibbet] || self.piratey_options[:gibbet],
|