lib/make_exportable/core.rb
# <tt>map_export_data</tt> takes a collection and outputs 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 and :except.
# See <tt>to_export</tt> for more details on the options.
#
#   User.map_export_data(User.visible, :only => [:first_name, :last_name, :username])
#   # => [['first_name', 'last_name', 'username'], ['John', 'Doe', 'johndoe'], ...]
#
map_export_data takes a collection and outputs 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 and :except.
See to_export for more details on the options.


map_export_data takes a collection and outputs 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 and : except . See to_export for more details on the options .
def map_export_data(collection, options={})
        if !options[:only].blank?
          options[:columns] = Array.wrap(options[:only]).map(&:to_sym)
        elsif !options[:except].blank?
          options[:columns] = column_names.map(&:to_sym) - Array.wrap(options[:except]).map(&:to_sym)
        else
          options[:columns] = exportable_options[:columns]
        end
        if options[:columns].empty?
          raise MakeExportable::ExportFault.new("You are not exporting anything")
        end
        headers = options[:columns].map(&:to_s)
        rows = collection.map do |item|
          options[:columns].map {|col| item.export_attribute(col) }
        end
        return rows.unshift(headers)
      end
def map_export_data ( collection , options = { } ) if ! options [ :only ] . blank? options [ :columns ] = Array . wrap ( options [ :only ] ) . map ( & :to_sym ) elsif ! options [ :except ] . blank? options [ :columns ] = column_names . map ( & :to_sym ) - Array . wrap ( options [ :except ] ) . map ( & :to_sym ) else options [ :columns ] = exportable_options [ :columns ] end if options [ :columns ] . empty? raise MakeExportable :: ExportFault . new ( "You are not exporting anything" ) end headers = options [ :columns ] . map ( & :to_s ) rows = collection . map do | item | options [ :columns ] . map { | col | item . export_attribute ( col ) } end return rows . unshift ( headers ) end
<tt>map_export_data</tt> takes a collection and outputs an array of arrays representing
the rows and columns of the export data.
<tt > map_export_data< / tt > takes a collection and outputs an array of arrays representing the rows and columns of the export data .
# Use :only and :except options or else use class defaults for columns. # TODO: Go ahead and humanize/titleize the column names here
collection
<not_specific>
options
<not_specific>