Skip to content

Instantly share code, notes, and snippets.

@parsonsmatt parsonsmatt/which_bar.rb
Last active Aug 29, 2015

Embed
What would you like to do?
muh filters
WhichBar =
Filter::Lift
| Filter::Singular.new(
attribute: :open,
value: true
)
| Filter::Collection.new(
attribute: :people,
aggregator: {
klass: :compare,
options: {
attribute: :age,
value: 21,
comparator: :>=,
reductor: :all?
}
}
)
Person = Struct.new(:age)
nope = (18..22).map(&Person.method(:new))
bad_news = (19..24).map(&Person.method(:new))
okay = (25..35).map(&Person.method(:new))
fine = (30..45).map(&Person.method(:new))
Bar = Struct.new(:people, :open)
trappeze = Bar.new(okay, true)
nineties = Bar.new(nope, true)
eighties = Bar.new(nope, false)
some_pig = Bar.new(fine, false)
bars = [trappeze, nineties, eighties, some_pig]
WhichBar.new(bars).records.first
=> trappeze
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.