Sha256: ea4d7d20be2ac12250a47178bf508fef0bf93496f7c6e6df3377c4783975d9e0
Contents?: true
Size: 974 Bytes
Versions: 5
Compression:
Stored size: 974 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' 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
5 entries across 5 versions & 1 rubygems