autotelik/datashift

View on GitHub
lib/datashift/generators/csv_generator.rb

Summary

Maintainability
A
0 mins
Test Coverage
# Copyright:: (c) Autotelik Media Ltd 2015
# Author ::   Tom Statter
# License::   MIT
#
# Details::   Create CSV file representing supplied Model
#
#
module DataShift

  class CsvGenerator < GeneratorBase

    attr_accessor :file_name

    def initialize(config: nil)
      super(config: config)
    end

    def generate(file_name, klass)
      @file_name = file_name

      headers = Headers.klass_to_headers(klass)

      logger.info("CSVGenerator saving generated Template #{@file_name}")

      csv_delim = DataShift::Exporters::Configuration.call.csv_delimiter

      CSV.open(file_name, 'w', col_sep: csv_delim ) do |csv|
        csv << headers.sources
      end

    end

  end
end