Sha256: 8f3894f7726ad5326a16a9508211aca6bad69556ff517e3d5378580517895ce4
Contents?: true
Size: 883 Bytes
Versions: 14
Compression:
Stored size: 883 Bytes
Contents
# frozen_string_literal: true require_relative '../column_instruction' class ActiveSet module Exporting class CSVStrategy require 'csv' def initialize(set, column_instructions) @set = set @column_instructions = column_instructions end def execute ::CSV.generate do |output| output << column_keys_for(item: @set.first) @set.each do |item| output << column_values_for(item: item) end end end private def column_keys_for(item:) columns.map do |column| ColumnInstruction.new(column, item).key end end def column_values_for(item:) columns.map do |column| ColumnInstruction.new(column, item).value end end def columns @column_instructions.compact end end end end
Version data entries
14 entries across 14 versions & 2 rubygems