csv_pirate 5.0.8 → 5.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +4 -1
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +18 -2
- data/CHANGELOG +7 -0
- data/LICENSE +1 -1
- data/README.md +507 -0
- data/REEK +129 -0
- data/csv_pirate.gemspec +3 -1
- data/gemfiles/Gemfile.activerecord-2.3.x +7 -0
- data/gemfiles/Gemfile.activerecord-3.0.x +7 -0
- data/gemfiles/Gemfile.activerecord-3.1.x +7 -0
- data/gemfiles/Gemfile.activerecord-3.2.x +7 -0
- data/gemfiles/Gemfile.activerecord-4.0.x +5 -0
- data/install.rb +1 -1
- data/lib/csv_pirate.rb +1 -1
- data/lib/csv_pirate/version.rb +1 -1
- data/spec/spec_helper.rb +6 -0
- metadata +30 -21
- data/README.rdoc +0 -464
data/REEK
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
lib/csv_pirate.rb -- 0 warnings
|
2
|
+
lib/csv_pirate/pirate_ship.rb -- 17 warnings:
|
3
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship calls options[:blackjack] 3 times (DuplicateMethodCall)
|
4
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship calls options[:booty] 4 times (DuplicateMethodCall)
|
5
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship calls options[:chart] 4 times (DuplicateMethodCall)
|
6
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship calls options[:gibbet] 3 times (DuplicateMethodCall)
|
7
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship calls options[:grub] 3 times (DuplicateMethodCall)
|
8
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship calls options[:grub].nil? twice (DuplicateMethodCall)
|
9
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship calls options[:mop] twice (DuplicateMethodCall)
|
10
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship calls options[:shrouds] 3 times (DuplicateMethodCall)
|
11
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship calls options[:swab] 3 times (DuplicateMethodCall)
|
12
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship calls options[:swag] 3 times (DuplicateMethodCall)
|
13
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship calls options[:swag].nil? 3 times (DuplicateMethodCall)
|
14
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship calls options[:waggoner] 3 times (DuplicateMethodCall)
|
15
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship has approx 31 statements (TooManyStatements)
|
16
|
+
CsvPirate::PirateShip::ActMethods#has_csv_pirate_ship refers to options more than self (FeatureEnvy)
|
17
|
+
CsvPirate::PirateShip::ClassMethods#get_chronometer calls self.piratey_options twice (DuplicateMethodCall)
|
18
|
+
CsvPirate::PirateShip::ClassMethods#get_chronometer calls self.piratey_options[:chronometer] twice (DuplicateMethodCall)
|
19
|
+
CsvPirate::PirateShip::ClassMethods#piratey_args calls self.piratey_options 14 times (DuplicateMethodCall)
|
20
|
+
lib/csv_pirate/railtie.rb -- 1 warning:
|
21
|
+
CsvPirate::Railtie has no descriptive comment (IrresponsibleModule)
|
22
|
+
lib/csv_pirate/the_capn.rb -- 106 warnings:
|
23
|
+
CsvPirate::TheCapn has at least 21 instance variables (TooManyInstanceVariables)
|
24
|
+
CsvPirate::TheCapn has at least 36 methods (TooManyMethods)
|
25
|
+
CsvPirate::TheCapn has no descriptive comment (IrresponsibleModule)
|
26
|
+
CsvPirate::TheCapn tests (TheCapn.parlay and TheCapn.parlance(1)) at least 4 times (RepeatedConditional)
|
27
|
+
CsvPirate::TheCapn tests TheCapn.parlance(1) at least 3 times (RepeatedConditional)
|
28
|
+
CsvPirate::TheCapn tests TheCapn.parlance(2) at least 8 times (RepeatedConditional)
|
29
|
+
CsvPirate::TheCapn tests obj.nil? at least 6 times (RepeatedConditional)
|
30
|
+
CsvPirate::TheCapn#binnacle calls compass.to_s twice (DuplicateMethodCall)
|
31
|
+
CsvPirate::TheCapn#binnacle has approx 7 statements (TooManyStatements)
|
32
|
+
CsvPirate::TheCapn#binnacle has boolean parameter 'humanize' (BooleanParameter)
|
33
|
+
CsvPirate::TheCapn#binnacle is controlled by argument humanize (ControlParameter)
|
34
|
+
CsvPirate::TheCapn#binnacle refers to compass more than self (FeatureEnvy)
|
35
|
+
CsvPirate::TheCapn#block_and_tackle has the variable name 'k' (UncommunicativeVariableName)
|
36
|
+
CsvPirate::TheCapn#block_and_tackle has the variable name 'v' (UncommunicativeVariableName)
|
37
|
+
CsvPirate::TheCapn#boatswain calls self.swabbie twice (DuplicateMethodCall)
|
38
|
+
CsvPirate::TheCapn#boatswain has approx 7 statements (TooManyStatements)
|
39
|
+
CsvPirate::TheCapn#coxswain calls self.swabbie twice (DuplicateMethodCall)
|
40
|
+
CsvPirate::TheCapn#data_hash_from_row calls my_booty.reject twice (DuplicateMethodCall)
|
41
|
+
CsvPirate::TheCapn#data_hash_from_row calls self.booty 4 times (DuplicateMethodCall)
|
42
|
+
CsvPirate::TheCapn#data_hash_from_row calls x.to_sym twice (DuplicateMethodCall)
|
43
|
+
CsvPirate::TheCapn#data_hash_from_row has approx 15 statements (TooManyStatements)
|
44
|
+
CsvPirate::TheCapn#data_hash_from_row has boolean parameter 'exclude_id' (BooleanParameter)
|
45
|
+
CsvPirate::TheCapn#data_hash_from_row has boolean parameter 'exclude_timestamps' (BooleanParameter)
|
46
|
+
CsvPirate::TheCapn#data_hash_from_row has the variable name 'a' (UncommunicativeVariableName)
|
47
|
+
CsvPirate::TheCapn#data_hash_from_row has the variable name 'x' (UncommunicativeVariableName)
|
48
|
+
CsvPirate::TheCapn#data_hash_from_row is controlled by argument exclude_id (ControlParameter)
|
49
|
+
CsvPirate::TheCapn#data_hash_from_row is controlled by argument exclude_timestamps (ControlParameter)
|
50
|
+
CsvPirate::TheCapn#dead_mans_chest calls self.maroon twice (DuplicateMethodCall)
|
51
|
+
CsvPirate::TheCapn#dig_for_treasure calls grub twice (DuplicateMethodCall)
|
52
|
+
CsvPirate::TheCapn#dig_for_treasure calls self.swag twice (DuplicateMethodCall)
|
53
|
+
CsvPirate::TheCapn#dig_for_treasure has the variable name 'x' (UncommunicativeVariableName)
|
54
|
+
CsvPirate::TheCapn#filibuster has approx 6 statements (TooManyStatements)
|
55
|
+
CsvPirate::TheCapn#filibuster refers to base more than self (FeatureEnvy)
|
56
|
+
CsvPirate::TheCapn#find_aye doesn't depend on instance state (UtilityFunction)
|
57
|
+
CsvPirate::TheCapn#find_aye refers to columns more than self (FeatureEnvy)
|
58
|
+
CsvPirate::TheCapn#find_aye_arr doesn't depend on instance state (UtilityFunction)
|
59
|
+
CsvPirate::TheCapn#find_aye_arr refers to col more than self (FeatureEnvy)
|
60
|
+
CsvPirate::TheCapn#find_aye_arr refers to columns more than self (FeatureEnvy)
|
61
|
+
CsvPirate::TheCapn#find_aye_arr refers to data_hash more than self (FeatureEnvy)
|
62
|
+
CsvPirate::TheCapn#flies has the variable name 'x' (UncommunicativeVariableName)
|
63
|
+
CsvPirate::TheCapn#initialize calls args.first 17 times (DuplicateMethodCall)
|
64
|
+
CsvPirate::TheCapn#initialize calls args.first[:chronometer] twice (DuplicateMethodCall)
|
65
|
+
CsvPirate::TheCapn#initialize calls self.astrolabe twice (DuplicateMethodCall)
|
66
|
+
CsvPirate::TheCapn#initialize calls self.blackjack twice (DuplicateMethodCall)
|
67
|
+
CsvPirate::TheCapn#initialize calls self.booty 4 times (DuplicateMethodCall)
|
68
|
+
CsvPirate::TheCapn#initialize calls self.brigantine twice (DuplicateMethodCall)
|
69
|
+
CsvPirate::TheCapn#initialize calls self.chart 4 times (DuplicateMethodCall)
|
70
|
+
CsvPirate::TheCapn#initialize calls self.gibbet 3 times (DuplicateMethodCall)
|
71
|
+
CsvPirate::TheCapn#initialize calls self.grub 4 times (DuplicateMethodCall)
|
72
|
+
CsvPirate::TheCapn#initialize calls self.grub.nil? twice (DuplicateMethodCall)
|
73
|
+
CsvPirate::TheCapn#initialize calls self.mop twice (DuplicateMethodCall)
|
74
|
+
CsvPirate::TheCapn#initialize calls self.shrouds 3 times (DuplicateMethodCall)
|
75
|
+
CsvPirate::TheCapn#initialize calls self.swab 3 times (DuplicateMethodCall)
|
76
|
+
CsvPirate::TheCapn#initialize calls self.swag 3 times (DuplicateMethodCall)
|
77
|
+
CsvPirate::TheCapn#initialize calls self.swag.nil? twice (DuplicateMethodCall)
|
78
|
+
CsvPirate::TheCapn#initialize calls self.waggoner 3 times (DuplicateMethodCall)
|
79
|
+
CsvPirate::TheCapn#jolly_roger calls TheCapn.parlance(1) 3 times (DuplicateMethodCall)
|
80
|
+
CsvPirate::TheCapn#jolly_roger calls TheCapn.parlay 3 times (DuplicateMethodCall)
|
81
|
+
CsvPirate::TheCapn#jolly_roger calls self.buried_treasure twice (DuplicateMethodCall)
|
82
|
+
CsvPirate::TheCapn#northwest_passage calls self.chart twice (DuplicateMethodCall)
|
83
|
+
CsvPirate::TheCapn#northwest_passage has the variable name 'i' (UncommunicativeVariableName)
|
84
|
+
CsvPirate::TheCapn#poop_deck calls self.analemma twice (DuplicateMethodCall)
|
85
|
+
CsvPirate::TheCapn#prize refers to plunder more than self (FeatureEnvy)
|
86
|
+
CsvPirate::TheCapn#run_through has the variable name 'k' (UncommunicativeVariableName)
|
87
|
+
CsvPirate::TheCapn#run_through has the variable name 'v' (UncommunicativeVariableName)
|
88
|
+
CsvPirate::TheCapn#sand_glass calls self.chronometer twice (DuplicateMethodCall)
|
89
|
+
CsvPirate::TheCapn#save_object has the variable name 'k' (UncommunicativeVariableName)
|
90
|
+
CsvPirate::TheCapn#save_object has the variable name 'v' (UncommunicativeVariableName)
|
91
|
+
CsvPirate::TheCapn#save_object refers to obj more than self (FeatureEnvy)
|
92
|
+
CsvPirate::TheCapn#self.create calls args.first 15 times (DuplicateMethodCall)
|
93
|
+
CsvPirate::TheCapn#self.marlinespike has approx 7 statements (TooManyStatements)
|
94
|
+
CsvPirate::TheCapn#self.mutiny calls TheCapn.parlance(1) twice (DuplicateMethodCall)
|
95
|
+
CsvPirate::TheCapn#self.mutiny calls TheCapn.parlance(2) 6 times (DuplicateMethodCall)
|
96
|
+
CsvPirate::TheCapn#self.mutiny calls carrack.grub 4 times (DuplicateMethodCall)
|
97
|
+
CsvPirate::TheCapn#self.mutiny calls carrack.spyglasses 7 times (DuplicateMethodCall)
|
98
|
+
CsvPirate::TheCapn#self.mutiny calls carrack.swag twice (DuplicateMethodCall)
|
99
|
+
CsvPirate::TheCapn#self.mutiny calls cutthroat.grub 8 times (DuplicateMethodCall)
|
100
|
+
CsvPirate::TheCapn#self.mutiny calls cutthroat.grub.class twice (DuplicateMethodCall)
|
101
|
+
CsvPirate::TheCapn#self.mutiny calls gully.send(carrack.spyglasses) twice (DuplicateMethodCall)
|
102
|
+
CsvPirate::TheCapn#self.mutiny contains iterators nested 2 deep (NestedIterators)
|
103
|
+
CsvPirate::TheCapn#self.mutiny has approx 26 statements (TooManyStatements)
|
104
|
+
CsvPirate::TheCapn#self.parlance calls self.parlay twice (DuplicateMethodCall)
|
105
|
+
CsvPirate::TheCapn#self.rinse contains iterators nested 2 deep (NestedIterators)
|
106
|
+
CsvPirate::TheCapn#send_aye calls self.find_aye_arr(data_hash, columns) twice (DuplicateMethodCall)
|
107
|
+
CsvPirate::TheCapn#send_aye calls self.grub twice (DuplicateMethodCall)
|
108
|
+
CsvPirate::TheCapn#sounding contains iterators nested 2 deep (NestedIterators)
|
109
|
+
CsvPirate::TheCapn#sounding has the variable name 'x' (UncommunicativeVariableName)
|
110
|
+
CsvPirate::TheCapn#to_memory calls (buccaneers << obj) 5 times (DuplicateMethodCall)
|
111
|
+
CsvPirate::TheCapn#to_memory calls (buccaneers << self.grub.new(data_hash)) twice (DuplicateMethodCall)
|
112
|
+
CsvPirate::TheCapn#to_memory calls obj.nil? 6 times (DuplicateMethodCall)
|
113
|
+
CsvPirate::TheCapn#to_memory calls obj.save(false) 3 times (DuplicateMethodCall)
|
114
|
+
CsvPirate::TheCapn#to_memory calls permanence[:find_or_create] twice (DuplicateMethodCall)
|
115
|
+
CsvPirate::TheCapn#to_memory calls permanence[:find_or_new] twice (DuplicateMethodCall)
|
116
|
+
CsvPirate::TheCapn#to_memory calls permanence[:find_or_save] twice (DuplicateMethodCall)
|
117
|
+
CsvPirate::TheCapn#to_memory calls permanence[:update_or_create] twice (DuplicateMethodCall)
|
118
|
+
CsvPirate::TheCapn#to_memory calls permanence[:update_or_new] twice (DuplicateMethodCall)
|
119
|
+
CsvPirate::TheCapn#to_memory calls permanence[:update_or_save] twice (DuplicateMethodCall)
|
120
|
+
CsvPirate::TheCapn#to_memory calls self.grub 10 times (DuplicateMethodCall)
|
121
|
+
CsvPirate::TheCapn#to_memory calls self.grub.create(data_hash) 3 times (DuplicateMethodCall)
|
122
|
+
CsvPirate::TheCapn#to_memory calls self.save_object(obj, data_hash) 3 times (DuplicateMethodCall)
|
123
|
+
CsvPirate::TheCapn#to_memory has approx 30 statements (TooManyStatements)
|
124
|
+
CsvPirate::TheCapn#to_memory has boolean parameter 'exclude_id' (BooleanParameter)
|
125
|
+
CsvPirate::TheCapn#to_memory has boolean parameter 'exclude_timestamps' (BooleanParameter)
|
126
|
+
CsvPirate::TheCapn#unfurl calls self.gibbet twice (DuplicateMethodCall)
|
127
|
+
CsvPirate::TheCapn#unfurl calls self.waggoner twice (DuplicateMethodCall)
|
128
|
+
CsvPirate::TheCapn#unfurl has approx 7 statements (TooManyStatements)
|
129
|
+
lib/csv_pirate/version.rb -- 0 warnings
|
data/csv_pirate.gemspec
CHANGED
@@ -11,7 +11,7 @@ It works better if you are wearing a tricorne!}
|
|
11
11
|
s.email = %q{peter.boling@gmail.com}
|
12
12
|
s.extra_rdoc_files = [
|
13
13
|
"LICENSE",
|
14
|
-
"README.
|
14
|
+
"README.md"
|
15
15
|
]
|
16
16
|
s.files = `git ls-files`.split($\)
|
17
17
|
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -28,4 +28,6 @@ It works better if you are wearing a tricorne!}
|
|
28
28
|
s.add_development_dependency(%q<reek>, [">= 1.2.8"])
|
29
29
|
s.add_development_dependency(%q<roodi>, [">= 2.1.0"])
|
30
30
|
s.add_development_dependency(%q<rake>, [">= 0"])
|
31
|
+
s.add_development_dependency "coveralls"
|
32
|
+
|
31
33
|
end
|
data/install.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
puts IO.read(File.join(File.dirname(__FILE__), 'README.
|
1
|
+
puts IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
data/lib/csv_pirate.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# CsvPirate
|
2
|
-
# Copyright ©2008-
|
2
|
+
# Copyright ©2008-2013 Peter H. Boling of RailsBling.com, released under the MIT license
|
3
3
|
# Gem / Plugin for Rails / Active Record: Easily make CSVs of anything that can be derived from your models
|
4
4
|
# Language: Ruby (written by a pirate)
|
5
5
|
# License: MIT License
|
data/lib/csv_pirate/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv_pirate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
5
|
-
prerelease:
|
4
|
+
version: 5.0.9
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Peter Boling
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-11-26 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: shoulda
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rdoc
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: reek
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ! '>='
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ! '>='
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -78,7 +69,6 @@ dependencies:
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: roodi
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ! '>='
|
84
74
|
- !ruby/object:Gem::Version
|
@@ -86,7 +76,6 @@ dependencies:
|
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
80
|
- - ! '>='
|
92
81
|
- !ruby/object:Gem::Version
|
@@ -94,7 +83,6 @@ dependencies:
|
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: rake
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
87
|
- - ! '>='
|
100
88
|
- !ruby/object:Gem::Version
|
@@ -102,7 +90,20 @@ dependencies:
|
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
107
|
requirements:
|
107
108
|
- - ! '>='
|
108
109
|
- !ruby/object:Gem::Version
|
@@ -116,20 +117,29 @@ executables: []
|
|
116
117
|
extensions: []
|
117
118
|
extra_rdoc_files:
|
118
119
|
- LICENSE
|
119
|
-
- README.
|
120
|
+
- README.md
|
120
121
|
files:
|
122
|
+
- .coveralls.yml
|
121
123
|
- .document
|
122
124
|
- .gitignore
|
125
|
+
- .ruby-gemset
|
126
|
+
- .ruby-version
|
123
127
|
- .travis.yml
|
124
128
|
- CHANGELOG
|
125
129
|
- Gemfile
|
126
130
|
- LICENSE
|
127
|
-
- README.
|
131
|
+
- README.md
|
132
|
+
- REEK
|
128
133
|
- Rakefile
|
129
134
|
- csv_pirate.gemspec
|
130
135
|
- features/csv_pirate.feature
|
131
136
|
- features/steps/csv_pirate_steps.rb
|
132
137
|
- features/support/env.rb
|
138
|
+
- gemfiles/Gemfile.activerecord-2.3.x
|
139
|
+
- gemfiles/Gemfile.activerecord-3.0.x
|
140
|
+
- gemfiles/Gemfile.activerecord-3.1.x
|
141
|
+
- gemfiles/Gemfile.activerecord-3.2.x
|
142
|
+
- gemfiles/Gemfile.activerecord-4.0.x
|
133
143
|
- install.rb
|
134
144
|
- lib/csv_pirate.rb
|
135
145
|
- lib/csv_pirate/pirate_ship.rb
|
@@ -148,27 +158,26 @@ files:
|
|
148
158
|
homepage: http://github.com/pboling/csv_pirate
|
149
159
|
licenses:
|
150
160
|
- MIT
|
161
|
+
metadata: {}
|
151
162
|
post_install_message:
|
152
163
|
rdoc_options: []
|
153
164
|
require_paths:
|
154
165
|
- lib
|
155
166
|
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
-
none: false
|
157
167
|
requirements:
|
158
168
|
- - ! '>='
|
159
169
|
- !ruby/object:Gem::Version
|
160
170
|
version: '0'
|
161
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
-
none: false
|
163
172
|
requirements:
|
164
173
|
- - ! '>='
|
165
174
|
- !ruby/object:Gem::Version
|
166
175
|
version: '0'
|
167
176
|
requirements: []
|
168
177
|
rubyforge_project:
|
169
|
-
rubygems_version: 1.
|
178
|
+
rubygems_version: 2.1.11
|
170
179
|
signing_key:
|
171
|
-
specification_version:
|
180
|
+
specification_version: 4
|
172
181
|
summary: Easily create CSVs of any data that can be derived from instance methods
|
173
182
|
on your classes.
|
174
183
|
test_files:
|
data/README.rdoc
DELETED
@@ -1,464 +0,0 @@
|
|
1
|
-
== CsvPirate {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/pboling/csv_pirate] {<img src="https://secure.travis-ci.org/pboling/csv_pirate.png?branch=master" alt="Build Status" />}[http://travis-ci.org/pboling/csv_pirate] {<img src="http://api.coderwall.com/pboling/endorsecount.png" />}[http://coderwall.com/pboling]
|
2
|
-
|
3
|
-
Easily create CSVs of any data that can be derived from your models.
|
4
|
-
|
5
|
-
CsvPirate is the easy way to create a CSV of essentially anything in Ruby, in full pirate regalia.
|
6
|
-
It works better if you are wearing a tricorne!
|
7
|
-
|
8
|
-
Compatible with:
|
9
|
-
|
10
|
-
Ruby 1.8.7 (Must also install/require 'faster_csv')
|
11
|
-
Ruby 1.9.2, 1.9.3, and 2.0.0
|
12
|
-
Rails 2, 3, and 4
|
13
|
-
|
14
|
-
Everything in the source that depended on Rails extensions of Ruby classes has been refactored to work in pure Ruby!
|
15
|
-
|
16
|
-
My goal is to have it do EVERYTHING it possibly can for me, since almost every project I do needs CSV exports.
|
17
|
-
|
18
|
-
CsvPirate only works for commissions of swag OR grub!
|
19
|
-
|
20
|
-
Initialize method (a.k.a new()) takes a hash of parameters, and creates the blank CSV file, and the instance can be modified prior to writing out to CSV:
|
21
|
-
|
22
|
-
# CsvPirate only works for commissions of swag OR grub!
|
23
|
-
# :swag the ARrr collection of swag to work on (optional)
|
24
|
-
# :grub the ARrr class that the spyglasses will be used on (optional)
|
25
|
-
# :spyglasses named scopes in your model that will refine the rows in the CSV according to conditions of the spyglasses,
|
26
|
-
# and order them according to the order of the spyglasses (optional)
|
27
|
-
# :booty booty (columns/methods) on your model that you want printed in the CSV, also used to create the figurehead (CSV header)
|
28
|
-
# :chart array of directory names (relative to rails root if using rails) which will be the filepath where you want to hide your loot
|
29
|
-
# :waggoner name of document where you will give detailed descriptions of the loot
|
30
|
-
# :aft filename extention ('.csv')
|
31
|
-
# :shrouds CSV column separator, default is ','. For tsv, tab-delimited, "\t"
|
32
|
-
# :chronometer keeps track of when you hunt for treasure
|
33
|
-
# :gibbet filename spacer after the date, and before the iterative counter/timestamp. MuST contain a '.'
|
34
|
-
# :swab can be :counter, :timestamp, or :none
|
35
|
-
# :counter - default, each successive run will create a new file using a counter
|
36
|
-
# :timestamp - each successive run will create a new file using a HHMMSS time stamp
|
37
|
-
# :none - no iterative file naming convention, just use waggoner and aft
|
38
|
-
# :mop can be :clean or :dirty (:overwrite or :append) (only has an effect if :swab is :none) since overwriting is irrelevant for a new file
|
39
|
-
# :clean - do not use :swab above (:counter or :timestamp), and instead overwrite the file
|
40
|
-
# :dirty - do not use :swab above (:counter, or :timestamp), and do not overwrite. Just keep adding on.
|
41
|
-
# :bury_treasure should we store the csv data as it is collected in an array in Ruby form for later use (true), or just write the CSV (false)?
|
42
|
-
# :blackjack Specify how you want your CSV header
|
43
|
-
# {:join => '-'} joins the method names called to get hte data for that column with '_' underscores.
|
44
|
-
# {:humanize =>'-'} first joins as above, then humanizes the string (this is the default)
|
45
|
-
# {:array => ['col1',col2','col3'] Uses the column names provided. If the array's length is less than the booty array's length it reverts to :humanize =>'_'
|
46
|
-
|
47
|
-
Check the source to see if there anything else hiding in there! (HINT: There a bunch more undocumented options)
|
48
|
-
|
49
|
-
The create method has the same parameters, and actually writes the data to the CSV.
|
50
|
-
|
51
|
-
Avast! Here be pirates! To brush up on pirate coding naming conventions:
|
52
|
-
|
53
|
-
http://www.privateerdragons.com/pirate_dictionary.html
|
54
|
-
|
55
|
-
== Install
|
56
|
-
|
57
|
-
[sudo] gem install csv_pirate
|
58
|
-
|
59
|
-
If you are still using Ruby < 1.9 then you will need to add fastercsv to your project.
|
60
|
-
FasterCSV became the built-in CSV library in Ruby 1.9, so is *only* required if using an older Ruby.
|
61
|
-
|
62
|
-
gem 'faster_csv', '>= 1.4.0'
|
63
|
-
|
64
|
-
== Upgrading
|
65
|
-
|
66
|
-
From version prior to 5.0
|
67
|
-
|
68
|
-
NinthBit::PirateShip::ActMethods has been deprecated in favor of CsvPirate::PirateShip::ActMethods.
|
69
|
-
Old API still works for now.
|
70
|
-
|
71
|
-
From version prior to 4.0
|
72
|
-
|
73
|
-
:chart was a string which indicated where you wanted to hide the loot (write the csv file)
|
74
|
-
Now it must be an array of directory names. So if you want your loot in "log/csv/pirates/model_name", then chart is:
|
75
|
-
['log','csv','pirates','model_name']
|
76
|
-
CsvPirate ensures that whatever you choose as your chart exists in the filesystem, and creates the directories if need be.
|
77
|
-
|
78
|
-
== Usage with ActiveRecord
|
79
|
-
|
80
|
-
What's the simplest thing that will work?
|
81
|
-
|
82
|
-
class MyClass < ActiveRecord::Base
|
83
|
-
has_csv_pirate_ship # defaults to csv of all columns of all records
|
84
|
-
end
|
85
|
-
|
86
|
-
MyClass.blindfold # creates the csv, and returns the CsvPirate instance
|
87
|
-
MyClass.walk_the_plank # creates the csv, and returns contents of the exported data (that was written into the csv) (as a string)
|
88
|
-
MyClass.land_ho # Does Not create the csv, sets up the CsvPirate instance. You can manipulate it and then call .hoist_mainstay on it to create the csv
|
89
|
-
|
90
|
-
== Importing to DB or Ruby objects in memory from CSV
|
91
|
-
|
92
|
-
Importing abilities are now here! You can dump data to CSV, copy the CSV to wherever, and then import the data in the CSV. Works very well with ActiveRecord.
|
93
|
-
|
94
|
-
See the weigh_anchor method, added to models with has_csv_pirate_ship defined, for dumping.
|
95
|
-
See the raise_anchor method, added to models with has_csv_pirate_ship defined, for importing.
|
96
|
-
See the to_memory method to convert the data in a csv or CsvPirate instance object back into Ruby class instances
|
97
|
-
with as many attributes as possible set equal to the data from the CSV.
|
98
|
-
|
99
|
-
== Usage without ActiveRecord
|
100
|
-
|
101
|
-
[ See Spec Tests for more Examples! ]
|
102
|
-
|
103
|
-
Since the defaults assume an active record class you need to override some of them:
|
104
|
-
|
105
|
-
class Star
|
106
|
-
extend CsvPirate::PirateShip::ActMethods
|
107
|
-
has_csv_pirate_ship :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels],
|
108
|
-
:spyglasses => [:get_stars]
|
109
|
-
|
110
|
-
attr_accessor :name, :distance, :spectral_type
|
111
|
-
|
112
|
-
def initialize(*args)
|
113
|
-
@name = args.first[:name]
|
114
|
-
@distance = args.first[:distance]
|
115
|
-
@spectral_type = args.first[:spectral_type]
|
116
|
-
end
|
117
|
-
|
118
|
-
def star_vowels
|
119
|
-
self.name.tr('aeiou', '*')
|
120
|
-
end
|
121
|
-
|
122
|
-
def self.get_stars
|
123
|
-
[
|
124
|
-
Star.new(:name => "Proxima Centauri", :distance => "4.2 LY", :spectral_type => "M5.5Vc"),
|
125
|
-
Star.new(:name => "Rigil Kentaurus", :distance => "4.3 LY", :spectral_type => "G2V"),
|
126
|
-
Star.new(:name => "Barnard's Star", :distance => "5.9 LY", :spectral_type => "M3.8V"),
|
127
|
-
Star.new(:name => "Wolf 359", :distance => "7.7 LY", :spectral_type => "M5.8Vc"),
|
128
|
-
Star.new(:name => "Lalande 21185", :distance => "8.26 LY", :spectral_type => "M2V"),
|
129
|
-
Star.new(:name => "Luyten 726-8A and B", :distance => "8.73 LY", :spectral_type => "M5.5 de & M6 Ve"),
|
130
|
-
Star.new(:name => "Sirius A and B", :distance => "8.6 LY", :spectral_type => "A1Vm"),
|
131
|
-
Star.new(:name => "Ross 154", :distance => "9.693 LY", :spectral_type => "M3.5"),
|
132
|
-
Star.new(:name => "Ross 248", :distance => "10.32 LY", :spectral_type => "M5.5V"),
|
133
|
-
Star.new(:name => "Epsilon Eridani", :distance => "10.5 LY", :spectral_type => "K2V")
|
134
|
-
]
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
|
139
|
-
rails development >a = Star.blindfold
|
140
|
-
=> #<CsvPirate:0x2209098 @buried_treasure=[], @mop=:clean, @spyglasses=[:get_stars], @swabbie=".3", @booty=[:name, :distance, :spectral_type, {:name=>:hash}, {:name=>:next}, {:name=>:upcase}, :star_vowels], @bury_treasure=false, @swab=:counter, @chronometer=Sun, 04 Oct 2009, @maroon="name,distance,spectral_type,namehash,namenext,nameupcase,star_vowels\nProxima Centauri,4.2 LY,M5.5Vc,971295636,Proxima Centaurj,PROXIMA CENTAURI,Pr*x*m* C*nt**r*\nRigil Kentaurus,4.3 LY,G2V,-231389024,Rigil Kentaurut,RIGIL KENTAURUS,R*g*l K*nt**r*s\nBarnard's Star,5.9 LY,M3.8V,1003964756,Barnard's Stas,BARNARD'S STAR,B*rn*rd's St*r\nWolf 359,7.7 LY,M5.8Vc,429493790,Wolf 360,WOLF 359,W*lf 359\nLalande 21185,8.26 LY,M2V,466625069,Lalande 21186,LALANDE 21185,L*l*nd* 21185\nLuyten 726-8A and B,8.73 LY,M5.5 de & M6 Ve,-886693495,Luyten 726-8A and C,LUYTEN 726-8A AND B,L*yt*n 726-8A *nd B\nSirius A and B,8.6 LY,A1Vm,-969980943,Sirius A and C,SIRIUS A AND B,S*r**s A *nd B\nRoss 154,9.693 LY,M3.5,-26506942,Ross 155,ROSS 154,R*ss 154\nRoss 248,10.32 LY,M5.5V,-18054910,Ross 249,ROSS 248,R*ss 248\nEpsilon Eridani,10.5 LY,K2V,931307088,Epsilon Eridanj,EPSILON ERIDANI,Eps*l*n Er*d*n*\n", @waggoner="Star", @astrolabe=false, @grub=Star, @rhumb_lines=#<File:/Users/pboling/RubymineProjects/empty_csv_pirate_app/log/csv/Star.20091004.export.3.csv (closed)>, @nocturnal="Star.20091004.export.3.csv", @aft=".csv", @gibbet=".export", @shrouds=",", @swag=[#<Star:0x2202db0 @spectral_type="M5.5Vc", @distance="4.2 LY", @name="Proxima Centauri">, #<Star:0x2202d10 @spectral_type="G2V", @distance="4.3 LY", @name="Rigil Kentaurus">, #<Star:0x2202c98 @spectral_type="M3.8V", @distance="5.9 LY", @name="Barnard's Star">, #<Star:0x2202c20 @spectral_type="M5.8Vc", @distance="7.7 LY", @name="Wolf 359">, #<Star:0x2202ba8 @spectral_type="M2V", @distance="8.26 LY", @name="Lalande 21185">, #<Star:0x2202b30 @spectral_type="M5.5 de & M6 Ve", @distance="8.73 LY", @name="Luyten 726-8A and B">, #<Star:0x2202ab8 @spectral_type="A1Vm", @distance="8.6 LY", @name="Sirius A and B">, #<Star:0x2202a40 @spectral_type="M3.5", @distance="9.693 LY", @name="Ross 154">, #<Star:0x22029c8 @spectral_type="M5.5V", @distance="10.32 LY", @name="Ross 248">, #<Star:0x2202950 @spectral_type="K2V", @distance="10.5 LY", @name="Epsilon Eridani">], @chart=["log", "csv"]>
|
141
|
-
rails development >a.weigh_anchor
|
142
|
-
name,distance,spectral_type,namehash,namenext,nameupcase,star_vowels
|
143
|
-
Proxima Centauri,4.2 LY,M5.5Vc,971295636,Proxima Centaurj,PROXIMA CENTAURI,Pr*x*m* C*nt**r*
|
144
|
-
Rigil Kentaurus,4.3 LY,G2V,-231389024,Rigil Kentaurut,RIGIL KENTAURUS,R*g*l K*nt**r*s
|
145
|
-
Barnard's Star,5.9 LY,M3.8V,1003964756,Barnard's Stas,BARNARD'S STAR,B*rn*rd's St*r
|
146
|
-
Wolf 359,7.7 LY,M5.8Vc,429493790,Wolf 360,WOLF 359,W*lf 359
|
147
|
-
Lalande 21185,8.26 LY,M2V,466625069,Lalande 21186,LALANDE 21185,L*l*nd* 21185
|
148
|
-
Luyten 726-8A and B,8.73 LY,M5.5 de & M6 Ve,-886693495,Luyten 726-8A and C,LUYTEN 726-8A AND B,L*yt*n 726-8A *nd B
|
149
|
-
Sirius A and B,8.6 LY,A1Vm,-969980943,Sirius A and C,SIRIUS A AND B,S*r**s A *nd B
|
150
|
-
Ross 154,9.693 LY,M3.5,-26506942,Ross 155,ROSS 154,R*ss 154
|
151
|
-
Ross 248,10.32 LY,M5.5V,-18054910,Ross 249,ROSS 248,R*ss 248
|
152
|
-
Epsilon Eridani,10.5 LY,K2V,931307088,Epsilon Eridanj,EPSILON ERIDANI,Eps*l*n Er*d*n*
|
153
|
-
=> #<File:/Users/pboling/RubymineProjects/empty_csv_pirate_app/log/csv/Star.20091004.export.3.csv (closed)>
|
154
|
-
|
155
|
-
== Advanced Usage & Examples
|
156
|
-
|
157
|
-
Assuming a Make (as in manufacturers of automobiles) model like this:
|
158
|
-
|
159
|
-
# == Schema Information
|
160
|
-
#
|
161
|
-
# Table name: makes
|
162
|
-
#
|
163
|
-
# id :integer(4) not null, primary key
|
164
|
-
# name :string(255)
|
165
|
-
# factory :string(255)
|
166
|
-
# sales :integer(4)
|
167
|
-
#
|
168
|
-
|
169
|
-
class Make < ActiveRecord::Base
|
170
|
-
has_many :vehicle_models
|
171
|
-
named_scope :factory_in_germany, :conditions => ["factory = ?", "Germany"]
|
172
|
-
|
173
|
-
# Showing all available options with their default values
|
174
|
-
has_csv_pirate_ship :chart => ['log','csv'] # Array of Strings: directory where csv will be created (Yes, it creates all of them if they do not already exist)
|
175
|
-
:aft => '.csv' # String: filename extension, usually this would be '.csv', but can be whatever you want.
|
176
|
-
:gibbet => '.export' # String: Middle part of the filename {the '.' is required for iterative filenames, set :swab => :none to turn off iterative filenames}
|
177
|
-
# Comes after waggoner and chronometer, before swabbie and aft
|
178
|
-
:waggoner => "#{Make}" # String: First part of filename
|
179
|
-
|
180
|
-
# Must provide :swag or :grub (not both)
|
181
|
-
: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)
|
182
|
-
: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).
|
183
|
-
: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.
|
184
|
-
: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...].
|
185
|
-
|
186
|
-
:swab => :counter # Symbol: What kind of file counter to use to avoid overwriting the CSV file, :counter is Integer, :timestamp is HHMMSS, :none is no file counter, increasing the likelihood of duplicate filenames on successive csv exports.
|
187
|
-
:mop => :clean # Symbol: If we DO end up writing to a preexisting file (by design or accident) should we overwrite (:clean) or append (:dirty)?
|
188
|
-
:shrouds => ',' # String: Delimiter for CSV. '\t' will create a tab delimited file (tsv), '|' will create a pipe delimited file.
|
189
|
-
:bury_treasure => true # Boolean: Should the array of objects in :swag be stored in the CsvPirate object for later inspection?
|
190
|
-
:blackjack => {:humanize => '-'} # Hash: Specify how you want your CSV header
|
191
|
-
# {:join => '-'} joins the method names called to get hte data for that column with '_' underscores.
|
192
|
-
# {:humanize => '-'} first joins as above, then humanizes the string (this is the default)
|
193
|
-
# {:array => ['col1',col2','col3'] Uses the column names provided in the array. If the array provided is too short defaults to :humanize =>'_'
|
194
|
-
|
195
|
-
# A customized version to create a tab delimited file for this class might look like this:
|
196
|
-
# has_csv_pirate_ship :spyglasses => [:factory_in_germany],
|
197
|
-
# :booty => [:id, :name],
|
198
|
-
# :shrouds => '\t'
|
199
|
-
# # keeping the rest of the options at the default values, so they don't need to be defined.
|
200
|
-
end
|
201
|
-
|
202
|
-
To create a csv of the names and ids of makes with factories in germany and return the text of the export:
|
203
|
-
|
204
|
-
Make.walk_the_plank # Get it? HA! If you can't believe I wrote this whole thing JUST to be able to make jokes like that... check ma sources :)
|
205
|
-
|
206
|
-
The name of the csv that comes out will be (by default located in log directory):
|
207
|
-
|
208
|
-
Make.20090930.export.13.csv
|
209
|
-
|
210
|
-
Where Make is the class, 20090930 is today's date, .export is the gibbet, and 13 is the iterative file counter, meaning I've run this export 13 times today.
|
211
|
-
|
212
|
-
All of those filename parts are customizable to a degree. For example if you want to have the date NOT be today's date you can supply your own date:
|
213
|
-
|
214
|
-
Make.walk_the_plank({:chronometer => Date.parse("December 21, 2012") })
|
215
|
-
# File name would be: Make.20121221.export.13.csv
|
216
|
-
|
217
|
-
Make.walk_the_plank({:chronometer => false })
|
218
|
-
# File name would be: Make.export.13.csv
|
219
|
-
|
220
|
-
What if you want the file name to be always the same and to always append to the end of it?
|
221
|
-
#Example: I want the file to be named "data", with no extension, both of the following accomplish that:
|
222
|
-
Make.walk_the_plank({:chronometer => false, :gibbet => "", :aft => "", :swab => :none, :waggoner => 'data'})
|
223
|
-
Make.blindfold(:chronometer => false, :gibbet => "", :aft => "", :swab => :none, :waggoner => 'data')
|
224
|
-
|
225
|
-
All of the options to has_csv_pirate_ship are available to walk_the_plank, land_ho, and blindfold, as well as to the raw class methods CsvPirate::TheCapn.new and CsvPirate::TheCapn.create, but not necessarily the other way around.
|
226
|
-
|
227
|
-
You can also customize the CSV, for example if you want to customize which columns are in the csv:
|
228
|
-
|
229
|
-
Make.walk_the_plank({:booty => [:id, :name, :sales]})
|
230
|
-
|
231
|
-
You want a timestamp file counter instead of the integer default:
|
232
|
-
|
233
|
-
Make.walk_the_plank({:booty => [:id, :name, :sales], :swab => :timestamp})
|
234
|
-
|
235
|
-
If you want to append each export to the end of the same file (on a per day basis):
|
236
|
-
|
237
|
-
Make.walk_the_plank({:booty => [:id, :name, :sales], :spyglasses => [:all], :swab => :none, :mop => :dirty})
|
238
|
-
|
239
|
-
If you want to restrict the csv to a particular set of named scopes:
|
240
|
-
|
241
|
-
Make.walk_the_plank({:booty => [:id, :name, :sales], :spyglasses => [:with_abs, :with_esc, :with_heated_seats]})
|
242
|
-
|
243
|
-
If you want to create a tsv (tab-delimited) or psv (pipe-delimited) instead of a csv:
|
244
|
-
|
245
|
-
Make.walk_the_plank({:booty => [:id, :name, :sales], :shrouds => '\t'})
|
246
|
-
Make.walk_the_plank({:booty => [:id, :name, :sales], :shrouds => '|'})
|
247
|
-
|
248
|
-
If you have a method in the Make class like this:
|
249
|
-
|
250
|
-
def to_slug
|
251
|
-
"#{self.name}_#{self.id}"
|
252
|
-
end
|
253
|
-
|
254
|
-
getting it in the CSV is easy peasy:
|
255
|
-
|
256
|
-
Make.walk_the_plank({:booty => [:id, :name, :to_slug]})
|
257
|
-
|
258
|
-
If you want to traverse Active Record Associations, or call a method on the return value of another method (unlimited nesting):
|
259
|
-
|
260
|
-
Make.walk_the_plank({:booty => [:id, :name, :to_slug, {:to_slug => :hash}]}) #will call .hash on the result of make.to_slug
|
261
|
-
Make.walk_the_plank({:booty => [:id, :name, :to_slug, {:to_slug => {:hash => :abs}}]}) #returns make.to_slug.hash.abs
|
262
|
-
|
263
|
-
If you want to build your booty using instance functions that require arguments, use an array:
|
264
|
-
Make.walk_the_plank({:booty => [:id, :name, [:value_on, Date.today]}) # will call make.value_on(Date.today)
|
265
|
-
|
266
|
-
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.
|
267
|
-
|
268
|
-
You can also use the raw CsvPirate class itself directly wherever you want.
|
269
|
-
|
270
|
-
The following two sets of code are identical:
|
271
|
-
|
272
|
-
csv_pirate = CsvPirate::TheCapn.new({
|
273
|
-
:grub => User,
|
274
|
-
:spyglasses => [:active,:logged_in],
|
275
|
-
:waggoner => 'active_users_logged_in',
|
276
|
-
:booty => ["id","number","login","created_at"],
|
277
|
-
:chart => ['log','csv']
|
278
|
-
})
|
279
|
-
csv_pirate.hoist_mainstay() # creates CSV file and writes out the rows
|
280
|
-
|
281
|
-
CsvPirate::TheCapn.create({
|
282
|
-
:grub => User,
|
283
|
-
:spyglasses => [:active,:logged_in],
|
284
|
-
:waggoner => 'active_users_logged_in',
|
285
|
-
:booty => ["id","number","login","created_at"],
|
286
|
-
:chart => ['log','csv']
|
287
|
-
})# creates CSV file and writes out the rows
|
288
|
-
|
289
|
-
Another example using swag instead of grub:
|
290
|
-
|
291
|
-
users = User.logged_out.inactive
|
292
|
-
csv_pirate = CsvPirate::TheCapn.new({
|
293
|
-
:swag => users,
|
294
|
-
:waggoner => 'inactive_users_not_logged_in',
|
295
|
-
:booty => ["id","number","login","created_at"],
|
296
|
-
:chart => ['log','csv']
|
297
|
-
})
|
298
|
-
csv_pirate.hoist_mainstay()
|
299
|
-
|
300
|
-
Then if you want to get your hands on the loot immediately:
|
301
|
-
|
302
|
-
csv_pirate.weigh_anchor()
|
303
|
-
|
304
|
-
For those who can't help but copy/paste into console and then edit:
|
305
|
-
|
306
|
-
csv_pirate = CsvPirate::TheCapn.new({:grub => User,:spyglasses => [:active,:logged_in],:waggoner => 'active_users_logged_in',:booty => ["id","number","login","created_at"],:chart => ['log','csv']})
|
307
|
-
|
308
|
-
OR
|
309
|
-
|
310
|
-
csv_pirate = CsvPirate::TheCapn.new({:swag => users,:waggoner => 'inactive_users_not_logged_in',:booty => ["id","number","login","created_at"],:chart => ['log','csv']})
|
311
|
-
|
312
|
-
|
313
|
-
== Downloading the CSV
|
314
|
-
|
315
|
-
You have the same Make class as above, and you have a MakeController:
|
316
|
-
|
317
|
-
class MakeController < ApplicationController
|
318
|
-
def download_csv
|
319
|
-
csv_pirate = Make.blindfold
|
320
|
-
|
321
|
-
# maroon saves the read to the file system, by using the text of the csv stored in the CsvPirate object.
|
322
|
-
send_data csv_pirate.maroon, ...
|
323
|
-
:type => 'text/csv; charset=iso-8859-1; header=present',
|
324
|
-
:disposition => "attachment; filename=#{csv_pirate.nocturnal}"
|
325
|
-
|
326
|
-
# However if CSVs are created using multiple CsvPirate objects that all append to a single file,
|
327
|
-
# we need to read the final product from the fs.
|
328
|
-
#send_file csv_pirate.brigantine,
|
329
|
-
# :type => 'text/csv; charset=utf-8; header=present',
|
330
|
-
# :disposition => "attachment; filename=#{csv_pirate.nocturnal}"
|
331
|
-
end
|
332
|
-
end
|
333
|
-
|
334
|
-
== Advanced Example with Nested Methods
|
335
|
-
|
336
|
-
You have a VehicleModel class and the same Make class as up above:
|
337
|
-
|
338
|
-
# == Schema Information
|
339
|
-
#
|
340
|
-
# Table name: vehicle_models
|
341
|
-
#
|
342
|
-
# id :integer(4) not null, primary key
|
343
|
-
# name :string(255)
|
344
|
-
# year :integer(4)
|
345
|
-
# horsepower :integer(4)
|
346
|
-
# price :integer(4)
|
347
|
-
# electric :boolean(1)
|
348
|
-
# make_id :integer(4)
|
349
|
-
#
|
350
|
-
|
351
|
-
class VehicleModel < ActiveRecord::Base
|
352
|
-
belongs_to :make
|
353
|
-
has_csv_pirate_ship :booty => [:id, :name, :year,
|
354
|
-
{:make => :name},
|
355
|
-
{:tires => {:size => {:width => :inches}}}]
|
356
|
-
def tires; TireSize.new; end
|
357
|
-
end
|
358
|
-
|
359
|
-
class TireSize
|
360
|
-
# To call an instance method you need to return an instance
|
361
|
-
def size; TireWidth.new; end
|
362
|
-
end
|
363
|
-
|
364
|
-
class TireWidth
|
365
|
-
# To call a class method you need to return the class object
|
366
|
-
def width; Measurement; end
|
367
|
-
end
|
368
|
-
|
369
|
-
class Measurement
|
370
|
-
def self.inches; 13; end
|
371
|
-
end
|
372
|
-
|
373
|
-
Then to create the CSV:
|
374
|
-
|
375
|
-
a = VehicleModel.blindfold
|
376
|
-
|
377
|
-
Then check the output from the console:
|
378
|
-
|
379
|
-
a.weigh_anchor
|
380
|
-
|
381
|
-
Id,Name,Year,Make name,Tires size width inches
|
382
|
-
1,Cavalier,1999,Chevrolet,13
|
383
|
-
2,Trailblazer,2006,Chevrolet,13
|
384
|
-
3,Corvette,2010,Chevrolet,13
|
385
|
-
4,Mustang,1976,Ford,13
|
386
|
-
5,Lebaron,1987,Chrysler,13
|
387
|
-
6,Avalon,1996,Toyota,13
|
388
|
-
=> #<File:/Users/pboling/RubymineProjects/empty_csv_pirate_app/log/VehicleModel.20091001.export.2.csv (closed)>
|
389
|
-
|
390
|
-
Joy to recursive code everywhere!
|
391
|
-
|
392
|
-
If you wanted to create the CsvPirate object and then modify it before creating the csv you can do that too.
|
393
|
-
Does not actually create the csv, so you need to do this in your code:
|
394
|
-
|
395
|
-
csv_pirate = VehicleModel.land_ho({:booty => [:id, :name, :year, :horsepower, :price]})
|
396
|
-
|
397
|
-
This allows you to modify the csv_pirate object before creating the csv like this:
|
398
|
-
|
399
|
-
csv_pirate.booty -= [:id, :name]
|
400
|
-
csv_pirate.hoist_mainstay()
|
401
|
-
|
402
|
-
== Tests
|
403
|
-
|
404
|
-
The tests are run with rspec. The test suite is expanding. Currently there is ample coverage of basic functionality.
|
405
|
-
|
406
|
-
If on a Ruby prior to Ruby 1.9 you will also need the fastercsv gem
|
407
|
-
|
408
|
-
To run tests cd to where ever you have csv_pirate installed, and do:
|
409
|
-
|
410
|
-
rake spec
|
411
|
-
|
412
|
-
== Compatibility with Micrsoft Excel
|
413
|
-
|
414
|
-
Microsoft Office (Excel) "SYLK Invalid Format" Error will occur if the string "ID" (without quotes)
|
415
|
-
is at the beginning of the CSV file. This is strangely inconvenient for rails CSVs since every table
|
416
|
-
in rails starts with an id column. So buyer beware... make your first column lower case 'id'
|
417
|
-
if you need to export the id field.
|
418
|
-
|
419
|
-
http://www.bradino.com/misc/sylk-file-format-is-not-valid/
|
420
|
-
|
421
|
-
== Contributing to CsvPirate
|
422
|
-
|
423
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
424
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
425
|
-
* Fork the project
|
426
|
-
* Start a feature/bugfix branch
|
427
|
-
* Commit and push until you are happy with your contribution
|
428
|
-
* Make sure to add tests, rspec preferred, for it. This is important so I don't break it in a future version unintentionally.
|
429
|
-
* Please try not to mess with the Rakefile, version, or change log. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
430
|
-
|
431
|
-
== On The Web
|
432
|
-
|
433
|
-
Source:
|
434
|
-
http://github.com/pboling/csv_pirate
|
435
|
-
|
436
|
-
Release Announcement:
|
437
|
-
http://galtzo.blogspot.com/2009/03/csv-pirate.html
|
438
|
-
|
439
|
-
== Versioning
|
440
|
-
|
441
|
-
This library aims to adhere to {Semantic Versioning 2.0.0}[http://semver.org/].
|
442
|
-
Violations of this scheme should be reported as bugs. Specifically,
|
443
|
-
if a minor or patch version is released that breaks backward
|
444
|
-
compatibility, a new version should be immediately released that
|
445
|
-
restores compatibility. Breaking changes to the public API will
|
446
|
-
only be introduced with new major versions.
|
447
|
-
|
448
|
-
As a result of this policy, you can (and should) specify a
|
449
|
-
dependency on this gem using the {Pessimistic Version Constraint}[http://docs.rubygems.org/read/chapter/16#page74] with two digits of precision.
|
450
|
-
|
451
|
-
For example:
|
452
|
-
|
453
|
-
spec.add_dependency 'csv_pirate', '~> 5.0'
|
454
|
-
|
455
|
-
== Thanks
|
456
|
-
|
457
|
-
Thanks go to:
|
458
|
-
|
459
|
-
* [Peter Boling](http://railsbling.com), author of CsvPirate, runs the joint.
|
460
|
-
* TimePerks LLC (http://www.timeperks.com) - Many useful enhancements were requested and paid for by TimePerks
|
461
|
-
|
462
|
-
----------------------------------------------------------------------------------
|
463
|
-
Author: Peter Boling, peter.boling at gmail dot com
|
464
|
-
Copyright (c) 2008-2013 Peter H. Boling of 9thBit LLC, released under the MIT license. See LICENSE for details.
|