README.rdoc in csv_pirate-3.3.2 vs README.rdoc in csv_pirate-3.4.1

- old
+ new

@@ -7,11 +7,11 @@ My goal is to have it do EVERYTHING it possibly can for me, since almost every project I do needs CSV exports. CsvPirate only works for commissions of swag OR grub! -Initialize method (a.k.a new()) takes a hash of params: +Initialize method (a.k.a new()) takes a hash of parameters: # CsvPirate only works for commissions of swag OR grub! # :swag the ARrr collection of swag to work on (optional) # :grub the ARrr class that the spyglasses will be used on (optional) # :spyglasses named scopes in your model that will refine the rows in the CSV according to conditions of the spyglasses, @@ -26,13 +26,17 @@ # :swab can be :counter, :timestamp, or :none # :counter - default, each successive run will create a new file using a counter # :timestamp - each successive run will create a new file using a HHMMSS time stamp # :none - no iterative file naming convention, just use waggoner and aft # :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 - # :clean - do not use :counter or :timestamp, and instead overwrite the file - # :dirty - do not use :counter, or :timestamp, or :overwrite. Just keep adding on. + # :clean - do not use :swab above (:counter or :timestamp), and instead overwrite the file + # :dirty - do not use :swab above (:counter, or :timestamp), and do not overwrite. Just keep adding on. # :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)? + # :blackjack Specify how you want your CSV header + # {:join => '-'} joins the method names called to get hte data for that column with '_' underscores. + # {:humanize =>'-'} first joins as above, then humanizes the string + # {: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 =>'_' # check the source to see if there anything else hiding in there! The create method has the same parameters, and actually creates the CSV. Avast! Here be pirates! To brush up on pirate coding naming conventions: @@ -61,11 +65,11 @@ mkdir -p ~/src cd ~/src git clone git://github.com/pboling/csv_pirate.git cd csv_pirate gem build csv_pirate.gemspec - sudo gem install csv_pirate-3.3.1.gem # (Or whatever version gets built) + sudo gem install csv_pirate-3.4.1.gem # (Or whatever version gets built) Then cd to your rails app to optionally freeze the gem into your app: rake gems:freeze GEM=csv_pirate @@ -185,35 +189,39 @@ :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. :mop => :clean # Symbol: If we DO end up writing to a preexisting file (by design or accident) should we overwrite (:clean) or append (:dirty)? :shrouds => ',' # String: Delimiter for CSV. '\t' will create a tab delimited file (tsv), '|' will create a pipe delimited file. :bury_treasure => true # Boolean: Should the array of objects in :swag be stored in the CsvPirate object for later inspection? + :blackjack => {:humanize => '-'} # Hash: Specify how you want your CSV header + # {:join => '-'} joins the method names called to get hte data for that column with '_' underscores. + # {:humanize => '-'} first joins as above, then humanizes the string + # {:array => ['col1',col2','col3'] Uses the column names provided in the array. If the array provided is too short defaults to :humanize =>'_' # A customized version to create a tab delimited file for this class might look like this: # has_csv_pirate_ship :spyglasses => [:factory_in_germany], # :booty => [:id, :name], # :shrouds => '\t' - # # kepping the rest of the options at the default values, so they don't need to be defined. + # # keeping the rest of the options at the default values, so they don't need to be defined. end To create a csv of the names and ids of makes with factories in germany and return the text of the export: 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 :) -The name of the csv that comes out will be (by defualt located in log directory): +The name of the csv that comes out will be (by default located in log directory): Make.20090930.export.13.csv 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. 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: Make.walk_the_plank({:chronometer => Date.parse("December 21, 2012") }) - # Filename would be: Make.20121221.export.13.csv + # File name would be: Make.20121221.export.13.csv Make.walk_the_plank({:chronometer => false }) - # Filename would be: Make.export.13.csv + # File name would be: Make.export.13.csv What if you want the file name to be always the same and to always append to the end of it? #Example: I want the file to be named "data", with no extension, both of the following accomplish that: Make.walk_the_plank({:chronometer => false, :gibbet => "", :aft => "", :swab => :none, :waggoner => 'data'}) Make.blindfold(:chronometer => false, :gibbet => "", :aft => "", :swab => :none, :waggoner => 'data') @@ -362,10 +370,10 @@ Then check the output from the console: a.weigh_anchor - id,name,year,makename,tiressizewidthinches + Id,Name,Year,Make name,Tires size width inches 1,Cavalier,1999,Chevrolet,13 2,Trailblazer,2006,Chevrolet,13 3,Corvette,2010,Chevrolet,13 4,Mustang,1976,Ford,13 5,Lebaron,1987,Chrysler,13