Class: Satisfactory::Root

Inherits:
Object
  • Object
show all
Defined in:
lib/satisfactory/root.rb

Overview

The root of the factory graph. This is where you begin creating records.

Since:

  • 0.2.0

Defined Under Namespace

Classes: FactoryNotDefinedError

Instance Method Summary collapse

Constructor Details

#initializeRoot

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Root.

Since:

  • 0.2.0



8
9
10
# File 'lib/satisfactory/root.rb', line 8

def initialize
  @root_records = Hash.new { |h, k| h[k] = [] }
end

Instance Method Details

#add(factory_name, **attributes) ⇒ Object

Add a top-level record to the root. This is your entry point into the factory graph, and the way to begin creating records.

Raises:

Since:

  • 0.2.0



15
16
17
18
19
20
21
22
23
# File 'lib/satisfactory/root.rb', line 15

def add(factory_name, **attributes)
  raise FactoryNotDefinedError, factory_name unless Satisfactory.factory_configurations.key?(factory_name)

  Satisfactory::Record.new(
    type: factory_name,
    upstream: self,
    attributes:,
  ).tap { |r| @root_records[factory_name] << r }
end

#createHash<Symbol, Array<ApplicationRecord>>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash<Symbol, Array<ApplicationRecord>>)

Since:

  • 0.2.0



27
28
29
30
31
# File 'lib/satisfactory/root.rb', line 27

def create
  @root_records.transform_values do |records|
    records.map(&:create_self)
  end
end

#to_planHash<Symbol, Array<Hash>>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash<Symbol, Array<Hash>>)

Since:

  • 0.2.0



35
36
37
38
39
# File 'lib/satisfactory/root.rb', line 35

def to_plan
  @root_records.transform_values do |records|
    records.map(&:build_plan)
  end
end

#upstreamnil

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (nil)

Since:

  • 0.2.0



43
44
45
# File 'lib/satisfactory/root.rb', line 43

def upstream
  nil
end