Class: Satisfactory::Collection
- Inherits:
-
Array
- Object
- Array
- Satisfactory::Collection
- Defined in:
- lib/satisfactory/collection.rb
Overview
Represents a collection of homogenous records.
Instance Attribute Summary collapse
- #upstream ⇒ Object readonly private
Instance Method Summary collapse
-
#and ⇒ Satisfactory::Record, Satisfactory::Collection
Delegates to the upstream record.
-
#and_same(upstream_type) ⇒ Satisfactory::Record, ...
(also: #return_to)
Locate the nearest ancestor of the given type.
- #build ⇒ Object private
- #build_plan ⇒ Object private
-
#create ⇒ Hash<Symbol, Array<ApplicationRecord>>
Delegates to the upstream record.
-
#initialize(*args, upstream:, **kwargs, &block) ⇒ Collection
constructor
private
A new instance of Collection.
-
#to_plan ⇒ Hash
Delegates to the upstream record.
-
#which_are ⇒ Satisfactory::Collection
(also: #which_is)
Calls #which_is on each entry in the collection.
-
#with ⇒ Satisfactory::Collection
(also: #each_with)
Calls #with on each entry in the collection.
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.
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
#upstream ⇒ Object (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.
13 14 15 |
# File 'lib/satisfactory/collection.rb', line 13 def upstream @upstream end |
Instance Method Details
#and ⇒ Satisfactory::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.
47 48 49 |
# File 'lib/satisfactory/collection.rb', line 47 def and_same(upstream_type) Satisfactory::UpstreamRecordFinder.new(upstream:).find(upstream_type) end |
#build ⇒ Object
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.
53 54 55 |
# File 'lib/satisfactory/collection.rb', line 53 def build flat_map(&:build) end |
#build_plan ⇒ Object
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.
58 59 60 |
# File 'lib/satisfactory/collection.rb', line 58 def build_plan flat_map(&:build_plan) end |
#create ⇒ Hash<Symbol, Array<ApplicationRecord>>
Delegates to the upstream record.
27 |
# File 'lib/satisfactory/collection.rb', line 27 delegate :and, :create, :to_plan, to: :upstream |
#to_plan ⇒ Hash
Delegates to the upstream record.
27 |
# File 'lib/satisfactory/collection.rb', line 27 delegate :and, :create, :to_plan, to: :upstream |
#which_are ⇒ Satisfactory::Collection Also known as: which_is
Calls #which_is on each entry in the collection.
41 42 43 |
# File 'lib/satisfactory/collection.rb', line 41 def which_are(...) self.class.new(map { |entry| entry.which_is(...) }, upstream:) end |
#with ⇒ Satisfactory::Collection Also known as: each_with
Calls #with on each entry in the collection.
32 33 34 |
# File 'lib/satisfactory/collection.rb', line 32 def with(...) self.class.new(map { |entry| entry.with(...) }, upstream:) end |