Sha256: a6a032a911ecf2c99a9fba01e171d28859b16f1020e8e67e84a1b4f73f41169e

Contents?: true

Size: 1.37 KB

Versions: 37

Compression:

Stored size: 1.37 KB

Contents

module Eco::API::UseCases::GraphQL::Samples::Location::Service
  module TreeToList
    module Output
      OUT_FOLDER      = 'sftp'.freeze
      OUT_TIME_FORMAT = '%Y%m%dT%H%M%S'.freeze
      OUT_FILENAME    = 'Location_Nodes.csv'.freeze
      OUT_HEADER      = %w[
        nodeId
        name
        parentId
        parentName
        archived
        archivedToken
        weight
        level_reference
      ].freeze

      private

      def generate_live_nodes_file(nodes_list)
        return unless generate_live_nodes_file?

        CSV.open(output_filename, "w") do |csv|
          csv << output_header
          nodes_list do |item|
            csv << item.values_at(*output_header)
          end
        end
        log(:info) { "Created file: #{output_filename}" }
      end

      def output_header
        self.class::OUT_HEADER
      end

      def generate_live_nodes_file?
        true
      end

      def output_filename
        @output_filename ||= File.join(output_folder, "#{timestamp}_#{output_file}")
      end

      def output_folder
        "#{config.active_enviro}/#{self.class::OUT_FOLDER}"
      end

      def output_file
        options.dig(:output, :file) || self.class::OUT_FILENAME
      end

      def timestamp(date = Time.now)
        date.strftime(self.class::OUT_TIME_FORMAT)
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.20 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.19 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.18 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.17 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.16 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.15 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.14 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.13 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.12 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.11 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.10 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.9 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.8 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.7 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.6 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.5 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.4 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.3 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb
eco-helpers-3.0.2 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb