Method: MakeExportable::ClassMethods#get_export_data

Defined in:
lib/make_exportable/core.rb

#get_export_data(options = {}) ⇒ Object

get_export_data finds records for export using a combination of the default export options and the argument options, and returns an array of arrays representing the rows and columns of the export data. The first item (“row”) in the array will be an array of strings to be used as column headers. Valid options include :only, :except, :scopes and the standard find options. See to_export for more details on the options.

Example:

User.get_export_data(:only => [:first_name, :last_name, :username])
# => [['first_name', 'last_name', 'username'], ['John', 'Doe', 'johndoe'], ['Joe', 'Smith', 'jsmith']] }


160
161
162
163
164
165
# File 'lib/make_exportable/core.rb', line 160

def get_export_data(options={})
  column_options = options.slice(:only, :except)
  records     = find_export_data(options)
  export_data = map_export_data(records, column_options)
  return export_data
end