Sha256: 5e590e088795b10ad8a1460b640833e8d905e182760ea6de79acc48a9c758fa0

Contents?: true

Size: 967 Bytes

Versions: 6

Compression:

Stored size: 967 Bytes

Contents

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

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

  def main(session, options, usecase)
    options[:end_get] = false
    tree_struct = Helper.treeify(Helper.csv_nodes(input_file))

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

  private

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

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

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

  def active_enviro
    config.active_enviro
  end
end

require_relative 'csv_to_tree_case/node'
require_relative 'csv_to_tree_case/nodes_cleaner'
require_relative 'csv_to_tree_case/treeify'
require_relative 'csv_to_tree_case/helper'

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
eco-helpers-2.5.8 lib/eco/api/usecases/default_cases/csv_to_tree_case.rb
eco-helpers-2.5.7 lib/eco/api/usecases/default_cases/csv_to_tree_case.rb
eco-helpers-2.5.6 lib/eco/api/usecases/default_cases/csv_to_tree_case.rb
eco-helpers-2.5.5 lib/eco/api/usecases/default_cases/csv_to_tree_case.rb
eco-helpers-2.5.4 lib/eco/api/usecases/default_cases/csv_to_tree_case.rb
eco-helpers-2.5.3 lib/eco/api/usecases/default_cases/csv_to_tree_case.rb