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(upstream:) ⇒ 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(upstream:) ⇒ 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.
9 10 11 12 |
# File 'lib/satisfactory/collection.rb', line 9 def initialize(*, upstream:, **, &) super(*, **, &) @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.
15 16 17 |
# File 'lib/satisfactory/collection.rb', line 15 def upstream @upstream end |
Instance Method Details
#and ⇒ Satisfactory::Record, Satisfactory::Collection
Delegates to the upstream record.
29 |
# File 'lib/satisfactory/collection.rb', line 29 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.
49 50 51 |
# File 'lib/satisfactory/collection.rb', line 49 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.
55 56 57 |
# File 'lib/satisfactory/collection.rb', line 55 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.
60 61 62 |
# File 'lib/satisfactory/collection.rb', line 60 def build_plan flat_map(&:build_plan) end |
#create ⇒ Hash<Symbol, Array<ApplicationRecord>>
Delegates to the upstream record.
29 |
# File 'lib/satisfactory/collection.rb', line 29 delegate :and, :create, :to_plan, to: :upstream |
#to_plan ⇒ Hash
Delegates to the upstream record.
29 |
# File 'lib/satisfactory/collection.rb', line 29 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.
43 44 45 |
# File 'lib/satisfactory/collection.rb', line 43 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.
34 35 36 |
# File 'lib/satisfactory/collection.rb', line 34 def with(...) self.class.new(map { |entry| entry.with(...) }, upstream:) end |