Sha256: 5fef593f7d8282832af2714f35bc12c78b53846b9c4941b03bcc57fa278f0523

Contents?: true

Size: 858 Bytes

Versions: 24

Compression:

Stored size: 858 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: ";").each_with_index do |row, index|
              yield row, index
            end
          end

          # Returns a StringIO
          def example_file(data)
            csv_data = ::CSV.generate(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

24 entries across 24 versions & 1 rubygems

Version Path
decidim-admin-0.27.9 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.27.8 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.27.7 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.27.6 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.26.10 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.26.9 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.27.5 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.26.8 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.27.4 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.27.3 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.26.7 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.26.5 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.27.2 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.27.1 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.26.4 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.27.0 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.26.3 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.27.0.rc2 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.27.0.rc1 lib/decidim/admin/import/readers/csv.rb
decidim-admin-0.26.2 lib/decidim/admin/import/readers/csv.rb