module Collectible::Collection::Finder

Public Instance Methods

find_by(**attributes) click to toggle source

@param attributes [Hash] A hash of arbitrary attributes to match against the collection @return [*] The first item in the collection that matches the specified attributes

# 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) click to toggle source

@param attributes [Hash] A hash of arbitrary attributes to match against the collection @return [ApplicationCollection] A collection of all items in the collection that match the specified attributes

# 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