Sha256: e2e1a582343e2e994173750cecdb98067593c90f8213c1e409bcdbfb7f6d0c9e
Contents?: true
Size: 1.15 KB
Versions: 15
Compression:
Stored size: 1.15 KB
Contents
# Copyright (c) 2008-2013 Michael Dvorkin and contributors. # # Fat Free CRM is freely distributable under the terms of MIT license. # See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ require "csv" module FatFreeCRM class ExportCSV # CSV export. Based on to_csv Rails plugin by Ary Djmal # https://github.com/arydjmal/to_csv #---------------------------------------------------------------------------- def self.from_array(items = []) return '' if items.empty? # Infer column types from the first item in the array klass = items.first.class columns = klass.columns.map(&:name).reject { |column| column =~ /password|token/ } columns << 'tags' if klass.taggable? CSV.generate do |csv| csv << columns.map { |column| klass.human_attribute_name(column) } items.each do |item| csv << columns.map do |column| if column == 'tags' item.tag_list.join(' ') else item.send(column) end end end end end end end
Version data entries
15 entries across 15 versions & 2 rubygems