Sha256: f7e89630ed6073606d370a7983ab3b28699b53b0fb7ae1453b4b5ea462379cf7

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

#
# Copyright (c) 2020-present, Blue Marble Payroll, LLC
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

module Burner
  module Library
    module Collection
      # Take an array of (denormalized) objects and create an object hierarchy from them.
      # Under the hood it uses Hashematics: https://github.com/bluemarblepayroll/hashematics.
      #
      # Expected Payload[register] input: array of objects.
      # Payload[register] output: An array of objects.
      class Graph < JobWithRegister
        attr_reader :key, :groups

        def initialize(
          key:,
          config: Hashematics::Configuration.new,
          name: '',
          register: DEFAULT_REGISTER
        )
          super(name: name, register: register)

          raise ArgumentError, 'key is required' if key.to_s.empty?

          @groups = Hashematics::Configuration.new(config).groups
          @key    = key.to_s

          freeze
        end

        def perform(output, payload)
          graph = Hashematics::Graph.new(groups).add(array(payload[register]))

          output.detail("Graphing: #{key}")

          payload[register] = graph.data(key)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
burner-1.12.0 lib/burner/library/collection/graph.rb
burner-1.11.0 lib/burner/library/collection/graph.rb
burner-1.10.0 lib/burner/library/collection/graph.rb
burner-1.9.0 lib/burner/library/collection/graph.rb
burner-1.9.0.pre.alpha lib/burner/library/collection/graph.rb
burner-1.8.0 lib/burner/library/collection/graph.rb
burner-1.7.0 lib/burner/library/collection/graph.rb
burner-1.7.0.pre.alpha lib/burner/library/collection/graph.rb