Class: MicroMicro::Collections::ItemsCollection
- Inherits:
-
BaseCollection
- Object
- BaseCollection
- MicroMicro::Collections::ItemsCollection
- Defined in:
- lib/micro_micro/collections/items_collection.rb
Instance Method Summary collapse
-
#find_by(**args, &block) ⇒ MicroMicro::Item?
Return the first Item from a search.
-
#to_a ⇒ Array<Hash{Symbol => Array<String, Hash>}>
Return an Array of this collection’s Items as Hashes.
-
#types ⇒ Array<String>
Retrieve an Array of this collection’s unique Item types.
-
#where(**args) {|item| ... } ⇒ MicroMicro::Collections::ItemsCollection
Recursively search this collection for Items matching the given conditions.
Methods inherited from BaseCollection
Constructor Details
This class inherits a constructor from MicroMicro::Collections::BaseCollection
Instance Method Details
permalink #find_by(**args, &block) ⇒ MicroMicro::Item?
Return the first Item from a search.
42 43 44 |
# File 'lib/micro_micro/collections/items_collection.rb', line 42 def find_by(**args, &block) where(**args, &block).first end |
permalink #to_a ⇒ Array<Hash{Symbol => Array<String, Hash>}>
Return an Array of this collection’s Items as Hashes.
51 52 53 |
# File 'lib/micro_micro/collections/items_collection.rb', line 51 def to_a map(&:to_h) end |
permalink #types ⇒ Array<String>
Retrieve an Array of this collection’s unique Item types.
60 61 62 |
# File 'lib/micro_micro/collections/items_collection.rb', line 60 def types @types ||= Set[*flat_map(&:types)].to_a.sort end |
permalink #where(**args) {|item| ... } ⇒ MicroMicro::Collections::ItemsCollection
Recursively search this collection for Items matching the given conditions.
If a Hash is supplied, the returned collection will include Items matching all conditions. Keys must be Symbols matching an instance method on Item and values may be either a String or an Array of Strings.
When passing a block, each Item in this collection is yielded to the block and the returned collection will include Items that cause the block to return a value other than false
or nil
.
91 92 93 94 95 |
# File 'lib/micro_micro/collections/items_collection.rb', line 91 def where(**args, &block) return self if args.none? && !block self.class.new(ItemsCollectionSearch.new.search(self, **args, &block)) end |