Sha256: e17d40faaf025404ffc24994df54da15040deede09626bebbbc5f8603b2f19a8

Contents?: true

Size: 929 Bytes

Versions: 13

Compression:

Stored size: 929 Bytes

Contents

# frozen_string_literal: true

require "csv"

module Decidim
  module Admin
    module Import
      module Readers
        # Imports any exported CSV file to local objects. It transforms the
        # import data using the creator into the final target objects.
        class CSV < Base
          MIME_TYPE = "text/csv"

          def self.first_data_index
            1
          end

          def read_rows
            ::CSV.read(file, col_sep: Decidim.default_csv_col_sep, encoding: "BOM|UTF-8").each_with_index do |row, index|
              yield row, index
            end
          end

          # Returns a StringIO
          def example_file(data)
            csv_data = ::CSV.generate(col_sep: Decidim.default_csv_col_sep) do |csv|
              data.each do |row|
                csv << row
              end
            end

            ::StringIO.new(csv_data)
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-admin-0.29.1 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.28.4 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.29.0 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.28.3 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.29.0.rc4 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.29.0.rc3 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.29.0.rc2 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.29.0.rc1 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.28.2 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.28.1 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.28.0 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.28.0.rc5 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.28.0.rc4 lib/decidim/admin/import/readers/csv.rb