Sha256: a842139c860665cff3bde2081167aa4e4cb2800791f0388cd0f7edbe1f476c7f

Contents?: true

Size: 983 Bytes

Versions: 20

Compression:

Stored size: 983 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
    log(: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

20 entries across 20 versions & 1 rubygems

Version Path
eco-helpers-3.0.4 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.3 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.2 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.1 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-3.0.0 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.25 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.24 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.23 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.22 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.21 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.20 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.19 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.18 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.17 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.16 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.15 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.14 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.13 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.12 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb
eco-helpers-2.7.4 lib/eco/api/usecases/default/locations/csv_to_tree_case.rb