Sha256: de28af3380e82910f9974c2e796f517ec439d9dd3414ca5e83adcc1d4f911320

Contents?: true

Size: 523 Bytes

Versions: 130

Compression:

Stored size: 523 Bytes

Contents

module ControllerMixins
  module CsvInstanceMethods
    require 'csv'

    def to_csv(objects, skip_attributes=[], delimiter= ",")
      return "" if objects.blank?
      objects_class = objects.first.class
      filtered_columns = objects_class.column_names - skip_attributes
      CSV.generate do |csv|
        csv << filtered_columns
        objects.each do |object|
          csv << filtered_columns.collect { |a| object.attributes[a].blank? ? '' : "'#{object.attributes[a]}'" }
        end
      end
    end
  end
end

Version data entries

130 entries across 130 versions & 1 rubygems

Version Path
it-logica-application-backbone-1.2.1 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.2.0 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.1.8 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.1.7 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.1.6 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.1.5 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.1.4 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.1.3 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.1.2 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.1.1 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.1.0 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.56 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.55 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.54 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.53 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.52 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.51 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.50 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.49 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.48 lib/controller_mixins/csv_instance_methods.rb