Sha256: b04f58823aaffcdd3f79e461666f2a1dc4b7ffbacee26b20f0d86c58e8caa69f

Contents?: true

Size: 585 Bytes

Versions: 1

Compression:

Stored size: 585 Bytes

Contents

# frozen_string_literal: true

require 'csv'

module KManager
  module Resources
    # Represents a CSV file resource.
    class CsvFileResource < KManager::Resources::FileResource
      def initialize(**opts)
        super(**opts)
        @type = :csv
      end

      def load_document
        data = []
        CSV.parse(content, headers: true, header_converters: :symbol).each do |row|
          data << row.to_h
        end
        document.data = data
      end

      # def debug
      #   tp self.document.data, self.document.data.first.to_h.keys
      # end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
k_manager-0.0.13 lib/k_manager/resources/csv_file_resource.rb