Sha256: 4547bdec2e6985f79882c89a32214f00dc31f134d83e80ff47cb094ad754c0ff

Contents?: true

Size: 1.09 KB

Versions: 17

Compression:

Stored size: 1.09 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

17 entries across 17 versions & 1 rubygems

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