Module ActiveRecord::Extensions::FindToCSV::InstanceMethods
In: lib/ar-extensions/csv.rb

Methods

Public Instance methods

Returns CSV data including header rows for the passed in options.

[Source]

     # File lib/ar-extensions/csv.rb, line 258
258:     def to_csv( options={} )
259:       FasterCSV.generate do |csv|
260:         headers = self.class.to_csv_headers( options )
261:         csv << headers if headers
262:         to_csv_data( options ).each{ |data| csv << data }
263:       end
264:     end

Returns CSV data without any header rows for the passed in options.

[Source]

     # File lib/ar-extensions/csv.rb, line 244
244:     def to_csv_data( options={} )
245:       fields = self.class.to_csv_fields( options ).fields
246:       data, model_data = [], fields.inject( [] ) { |arr,field| arr << attributes[field].to_s }
247:       if options[:include]
248:         to_csv_data_for_included_associations( options[:include ] ).map do |assoc_csv_data|
249:           data << model_data + assoc_csv_data
250:         end
251:       else
252:         data << model_data
253:       end
254:       data
255:     end

[Validate]