Module: ActiveRecord::Extensions::FindToCSV::ArrayInstanceMethods
- Defined in:
- lib/ar-extensions/csv.rb
Overview
:nodoc:
Defined Under Namespace
Classes: NoRecordsError
Instance Method Summary collapse
-
#to_csv(options = {}) ⇒ Object
Returns CSV data with headers for an array of ActiveRecord::Base model objects by iterating over them and calling to_csv with the passed in
options. -
#to_csv_data(options = {}) ⇒ Object
Returns CSV data without headers for an array of ActiveRecord::Base model objects by iterating over them and calling to_csv_data with the passed in
options. -
#to_csv_headers(options = {}) ⇒ Object
Returns CSV headers for an array of ActiveRecord::Base model objects by calling to_csv_headers on the first element.
Instance Method Details
#to_csv(options = {}) ⇒ Object
Returns CSV data with headers for an array of ActiveRecord::Base model objects by iterating over them and calling to_csv with the passed in options.
290 291 292 293 294 295 296 297 298 |
# File 'lib/ar-extensions/csv.rb', line 290 def to_csv( ={} ) FasterCSV.generate do |csv| headers = to_csv_headers( ) csv << headers if headers each do |model_instance| model_instance.to_csv_data( ).each{ |data| csv << data } end end end |
#to_csv_data(options = {}) ⇒ Object
Returns CSV data without headers for an array of ActiveRecord::Base model objects by iterating over them and calling to_csv_data with the passed in options.
281 282 283 284 285 |
# File 'lib/ar-extensions/csv.rb', line 281 def to_csv_data( ={} ) inject( [] ) do |arr,model_instance| arr.push( *model_instance.to_csv_data( ) ) end end |
#to_csv_headers(options = {}) ⇒ Object
Returns CSV headers for an array of ActiveRecord::Base model objects by calling to_csv_headers on the first element.
274 275 276 |
# File 'lib/ar-extensions/csv.rb', line 274 def to_csv_headers( ={} ) first.class.to_csv_headers( ) end |