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.0.6 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.5 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.4 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.3 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.2 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.1 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-1.0.0 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-0.2.33 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-0.2.32 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-0.2.31 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-0.2.30 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-0.2.29 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-0.2.28 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-0.2.27 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-0.2.26 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-0.2.25 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-0.2.24 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-0.2.23 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-0.2.22 lib/controller_mixins/csv_instance_methods.rb
it-logica-application-backbone-0.2.21 lib/controller_mixins/csv_instance_methods.rb