Sha256: 2adc82d4c1b801d79593a22549941fbba74fb8db4d1c686c8a683cd636e31a37

Contents?: true

Size: 1.08 KB

Versions: 13

Compression:

Stored size: 1.08 KB

Contents

require_relative 'converter/parser'
require_relative 'converter/input'
require_relative 'converter/node_attr_maps'
require_relative 'converter/discarded'

module Eco::API::UseCases::GraphQL::Samples::Location::Service
  module TreeToList
    module Converter
      include Parser
      include Input
      include NodeAttrMaps
      include Discarded

      private

      # Converter. Transforms an org tagtree to a list of hash nodes
      # @note it ensures `DISCARDED_NODES` are excluded
      # @return [Array<Hash>] list of hash nodes
      def as_nodes_json(tree = input_tagtree)
        tree.reject do |node|
          discarded?(node.id)
        end.each_with_object([]) do |node, list|
          list << node.as_json(include_children: false).transform_keys do |key|
            next key unless node_attr_maps.key?(key)
            node_attr_maps[key]
          end.tap do |node_hash|
            node_parser_block&.call(node_hash, node)
            yield(node_hash, node) if block_given?
          end
        end.compact.reject(&:empty?)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
eco-helpers-3.0.4 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-3.0.3 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-3.0.2 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-3.0.1 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-3.0.0 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.25 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.24 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.23 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.22 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.21 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.20 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.19 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.18 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb