Module: Collectible::Collection::Finder
- Extended by:
- ActiveSupport::Concern
- Included in:
- Collectible::CollectionBase
- Defined in:
- lib/collectible/collection/finder.rb
Instance Method Summary collapse
-
#find_by(**attributes) ⇒ *
The first item in the collection that matches the specified attributes.
-
#where(**attributes) ⇒ ApplicationCollection
A collection of all items in the collection that match the specified attributes.
Instance Method Details
#find_by(**attributes) ⇒ *
Returns The first item in the collection that matches the specified attributes.
10 11 12 13 14 15 16 |
# File 'lib/collectible/collection/finder.rb', line 10 def find_by(**attributes) find do |item| attributes.all? do |attribute, value| item.public_send(attribute) == value end end end |
#where(**attributes) ⇒ ApplicationCollection
Returns A collection of all items in the collection that match the specified attributes.
20 21 22 23 24 25 26 |
# File 'lib/collectible/collection/finder.rb', line 20 def where(**attributes) select do |item| attributes.all? do |attribute, value| item.public_send(attribute) == value end end end |