Sha256: 6aa15cbdac8974f53d1c99c36dfa3705b084b84378d133c8203aec529563ed68
Contents?: true
Size: 968 Bytes
Versions: 2
Compression:
Stored size: 968 Bytes
Contents
class Eco::API::UseCases::DefaultCases::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' 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
eco-helpers-2.5.10 | lib/eco/api/usecases/default_cases/csv_to_tree_case.rb |
eco-helpers-2.5.9 | lib/eco/api/usecases/default_cases/csv_to_tree_case.rb |