Sha256: f7afaa9749de962dee88fc35662a03b651f137261c705f0be6f183c9ae705163

Contents?: true

Size: 1.12 KB

Versions: 17

Compression:

Stored size: 1.12 KB

Contents

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

  require_relative 'cli/csv_to_tree_cli'

  include Eco::Data::Locations::DSL

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

  def main(*_args)
    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
    log(:info) { "Saved structure in '#{output_file}'" }
  end

  private

  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 output_file
    @output_file ||= File.join(output_folder, output_base_name)
  end

  def output_base_name
    "#{active_enviro}_tree_#{timestamp}.json"
  end

  def output_folder
    File.dirname(input_file)
  end

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

  def active_enviro
    config.active_enviro
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.20 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.19 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.18 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.17 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.16 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.15 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.14 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.13 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.12 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.11 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.10 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.9 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.8 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.7 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.6 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.5 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb