Sha256: 3302c31dcf20e20ddbc5cc44272f5eb20b4e87411292fc35fe53a07e047b6770
Contents?: true
Size: 1.14 KB
Versions: 4
Compression:
Stored size: 1.14 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' 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
4 entries across 4 versions & 1 rubygems