Sha256: 9e76d5a58c319ef4e40a05234aa93705e13e44285da252d8861e306051bcee95

Contents?: true

Size: 981 Bytes

Versions: 3

Compression:

Stored size: 981 Bytes

Contents

class Eco::API::UseCases::Default::Locations::CsvToTree < Eco::API::Common::Loaders::UseCase
  name "csv-to-tree"
  type :other

  include Eco::Data::Locations::DSL

  TIME_FORMAT = '%Y%m%dT%H%M%S'.freeze

  def main(_session, options, _usecase)
    options[:end_get] = false
    tree_struct = org_tree(input_csv)

    File.open(output_file, "w") do |fd|
      fd << tree_struct.as_json.to_json
    end
    logger.info("Saved structure in '#{output_file}'")
  end

  private

  def output_file
    @output_file ||= "#{active_enviro}_tree_#{timestamp}.json"
  end

  def input_csv
    @input_csv ||= Eco::CSV.read(input_file, encoding: input_encoding)
  end

  def input_file
    @input_file ||= options.dig(:source, :file)
  end

  def input_encoding
    options.dig(:input, :file, :encoding) || 'utf-8'
  end

  def timestamp(date = Time.now)
    date.strftime(TIME_FORMAT)
  end

  def active_enviro
    config.active_enviro
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eco-helpers-2.7.2 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.1 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.0 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb