Sha256: e48b5eb78ffdcfbcbf3e04b7775ac6dcbe61d80506a7da917a28540d4f51fa98

Contents?: true

Size: 1.12 KB

Versions: 10

Compression:

Stored size: 1.12 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)
            yield(node_hash) if block_given?
          end
        end.tap do |list|
          list.each(&node_parser_block)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
eco-helpers-2.7.17 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.16 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.15 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.14 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.13 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.12 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.4 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.2 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.1 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb
eco-helpers-2.7.0 lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb