Class: Satisfactory::Collection

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

Overview

Represents a collection of homogenous records.

Since:

  • 0.2.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, upstream:, **kwargs, &block) ⇒ Collection

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 Collection.

Since:

  • 0.2.0



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

def initialize(*args, upstream:, **kwargs, &block)
  super(*args, **kwargs, &block)
  @upstream = upstream
end

Instance Attribute Details

#upstreamObject (readonly)

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.

Since:

  • 0.2.0



13
14
15
# File 'lib/satisfactory/collection.rb', line 13

def upstream
  @upstream
end

Instance Method Details

#andSatisfactory::Record, Satisfactory::Collection

Delegates to the upstream record.



27
# File 'lib/satisfactory/collection.rb', line 27

delegate :and, :create, :to_plan, to: :upstream

#and_same(upstream_type) ⇒ Satisfactory::Record, ... Also known as: return_to

Locate the nearest ancestor of the given type.

Parameters:

  • upstream_type (Symbol)

    The type of ancestor to find.

Returns:

Since:

  • 0.2.0



47
48
49
# File 'lib/satisfactory/collection.rb', line 47

def and_same(upstream_type)
  Satisfactory::UpstreamRecordFinder.new(upstream:).find(upstream_type)
end

#buildObject

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.

Since:

  • 0.2.0



53
54
55
# File 'lib/satisfactory/collection.rb', line 53

def build
  flat_map(&:build)
end

#build_planObject

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.

Since:

  • 0.2.0



58
59
60
# File 'lib/satisfactory/collection.rb', line 58

def build_plan
  flat_map(&:build_plan)
end

#createHash<Symbol, Array<ApplicationRecord>>

Delegates to the upstream record.

Returns:

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

See Also:



27
# File 'lib/satisfactory/collection.rb', line 27

delegate :and, :create, :to_plan, to: :upstream

#to_planHash

Delegates to the upstream record.

Returns:

  • (Hash)

See Also:



27
# File 'lib/satisfactory/collection.rb', line 27

delegate :and, :create, :to_plan, to: :upstream

#which_areSatisfactory::Collection Also known as: which_is

Calls #which_is on each entry in the collection.

Parameters:

  • traits (Symbol, ...)

    The traits to apply.

Returns:

Since:

  • 0.2.0



41
42
43
# File 'lib/satisfactory/collection.rb', line 41

def which_are(...)
  self.class.new(map { |entry| entry.which_is(...) }, upstream:)
end

#withSatisfactory::Collection Also known as: each_with

Calls #with on each entry in the collection.

Returns:

Since:

  • 0.2.0



32
33
34
# File 'lib/satisfactory/collection.rb', line 32

def with(...)
  self.class.new(map { |entry| entry.with(...) }, upstream:)
end