Class: Burner::Library::Collection::Graph

Inherits:
JobWithRegister show all
Defined in:
lib/burner/library/collection/graph.rb

Overview

Take an array of (denormalized) objects and create an object hierarchy from them. Under the hood it uses Hashematics: github.com/bluemarblepayroll/hashematics.

Expected Payload input: array of objects. Payload output: An array of objects.

Constant Summary

Constants inherited from JobWithRegister

JobWithRegister::BLANK

Instance Attribute Summary collapse

Attributes inherited from JobWithRegister

#register

Attributes inherited from Job

#name

Instance Method Summary collapse

Methods included from Util::Arrayable

#array

Constructor Details

#initialize(key:, config: Hashematics::Configuration.new, name: '', register: DEFAULT_REGISTER) ⇒ Graph

Returns a new instance of Graph.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/burner/library/collection/graph.rb', line 21

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

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



19
20
21
# File 'lib/burner/library/collection/graph.rb', line 19

def groups
  @groups
end

#keyObject (readonly)

Returns the value of attribute key.



19
20
21
# File 'lib/burner/library/collection/graph.rb', line 19

def key
  @key
end

Instance Method Details

#perform(output, payload) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/burner/library/collection/graph.rb', line 37

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

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

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