README.rdoc in csv_pirate-2.0.1 vs README.rdoc in csv_pirate-2.1.1
- old
+ new
@@ -181,9 +181,66 @@
OR
csv_pirate = CsvPirate.new({:swag => users,:waggoner => 'inactive_users_not_logged_in',:booty => ["id","number","login","created_at"],:chart => 'log/csv/'})
+== Advanced Example with Nested Methods
+
+You have a VehicleModel class and the same Make class as up above:
+
+ # == Schema Information
+ #
+ # Table name: vehicle_models
+ #
+ # id :integer(4) not null, primary key
+ # name :string(255)
+ # year :integer(4)
+ # horsepower :integer(4)
+ # price :integer(4)
+ # electric :boolean(1)
+ # make_id :integer(4)
+ #
+
+ class VehicleModel < ActiveRecord::Base
+ belongs_to :make
+ has_csv_pirate_ship :booty => [:id, :name, :year,
+ {:make => :name},
+ {:tires => {:size => {:width => :inches}}}]
+ def tires; TireSize.new; end
+ end
+
+ class TireSize
+ # To call an instance method you need to return an instance
+ def size; TireWidth.new; end
+ end
+
+ class TireWidth
+ # To call a class method you need to return the class object
+ def width; Measurement; end
+ end
+
+ class Measurement
+ def self.inches; 13; end
+ end
+
+Then to create the CSV:
+
+ a = VehicleModel.walk_the_plank
+
+Then check the output from the console:
+
+ a.weigh_anchor
+
+ id,name,year,makename,tiressizewidthinches
+ 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
+ 6,Avalon,1996,Toyota,13
+ => #<File:/Users/pboling/RubymineProjects/empty_csv_pirate_app/log/VehicleModel.20091001.export.2.csv (closed)>
+
+Joy to recursive code everywhere!
----------------------------------------------------------------------------------
Author: Peter Boling, peter.boling at gmail dot com
Copyright (c) 2009 Peter H. Boling of 9thBit LLC, released under the MIT license. See LICENSE for details.