README.rdoc in csv_pirate-5.0.6 vs README.rdoc in csv_pirate-5.0.7

- old
+ new

@@ -1,9 +1,7 @@ -== CsvPirate +== 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] -{<img src="https://secure.travis-ci.org/pboling/csv_pirate.png?branch=master" alt="Build Status" />}[http://travis-ci.org/pboling/csv_pirate] <= This cake is a lie. I am not sure why Travis is failing me. - Easily create CSVs of any data that can be derived from your models. CsvPirate is the easy way to create a CSV of essentially anything in Ruby, in full pirate regalia. It works better if you are wearing a tricorne! Now compatible with Ruby 1.8.7 & 1.9.2, and Rails 2 & 3! @@ -20,11 +18,11 @@ # :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, # and order them according to the order of the spyglasses (optional) # :booty booty (columns/methods) on your model that you want printed in the CSV, also used to create the figurehead (CSV header) # :chart array of directory names (relative to rails root if using rails) which will be the filepath where you want to hide your loot - # :wagonner name of document where you will give detailed descriptions of the loot + # :waggoner name of document where you will give detailed descriptions of the loot # :aft filename extention ('.csv') # :shrouds CSV column separator, default is ','. For tsv, tab-delimited, "\t" # :chronometer keeps track of when you hunt for treasure # :gibbet filename spacer after the date, and before the iterative counter/timestamp. MuST contain a '.' # :swab can be :counter, :timestamp, or :none @@ -103,11 +101,11 @@ def initialize(*args) @name = args.first[:name] @distance = args.first[:distance] @spectral_type = args.first[:spectral_type] end - + def star_vowels self.name.tr('aeiou', '*') end def self.get_stars @@ -172,11 +170,11 @@ :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) :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). :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. :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...]. - :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. + :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. :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. @@ -211,11 +209,11 @@ 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') -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.new and CsvPirate.create, but not neccessarily the other way around. +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. You can also customize the CSV, for example if you want to customize which columns are in the csv: Make.walk_the_plank({:booty => [:id, :name, :sales]}) @@ -258,31 +256,31 @@ You can also use the raw CsvPirate class itself directly wherever you want. The following two sets of code are identical: - csv_pirate = CsvPirate.new({ + 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'] }) csv_pirate.hoist_mainstay() # creates CSV file and writes out the rows - CsvPirate.create({ + CsvPirate::TheCapn.create({ :grub => User, :spyglasses => [:active,:logged_in], :waggoner => 'active_users_logged_in', :booty => ["id","number","login","created_at"], :chart => ['log','csv'] })# creates CSV file and writes out the rows Another example using swag instead of grub: users = User.logged_out.inactive - csv_pirate = CsvPirate.new({ + csv_pirate = CsvPirate::TheCapn.new({ :swag => users, :waggoner => 'inactive_users_not_logged_in', :booty => ["id","number","login","created_at"], :chart => ['log','csv'] }) @@ -292,14 +290,14 @@ csv_pirate.weigh_anchor() For those who can't help but copy/paste into console and then edit: - csv_pirate = CsvPirate.new({:grub => User,:spyglasses => [:active,:logged_in],:waggoner => 'active_users_logged_in',:booty => ["id","number","login","created_at"],:chart => ['log','csv']}) + 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']}) OR - csv_pirate = CsvPirate.new({:swag => users,:waggoner => 'inactive_users_not_logged_in',:booty => ["id","number","login","created_at"],:chart => ['log','csv']}) + csv_pirate = CsvPirate::TheCapn.new({:swag => users,:waggoner => 'inactive_users_not_logged_in',:booty => ["id","number","login","created_at"],:chart => ['log','csv']}) == Downloading the CSV You have the same Make class as above, and you have a MakeController: