module Philtre

The high-level interface to Philtre. There are several ways to use it:

  1. Philtre.new

    philtre = Philtre.new name: 'Moustafa'
    
  2. Philtre

    philtre = Philtre dataset: some_dataset, age_gt: 21
    philtre = Philtre dataset: some_dataset, with {age_gt: 21}
  3. Philtre.filter

    philtre = Philtre.filter dataset: some_dataset, name: 'Moustafa', age_gt: 21
    philtre = Philtre.filter dataset: some_dataset, with: {name: 'Moustafa', age_gt: 21}
    

Public Class Methods

filter( dataset: nil, with: {}, **kwargs ) click to toggle source

This is the high-level, easy-to-read smalltalk-style interface params:

  • dataset is a Sequel::Model or a Sequel::Dataset

  • with is the param hash (optional, or just use hash-style args)

for x-ample, in rails you could do

@personages = Philtre.filter dataset: Personage, with: params[:filter]

or even

@personages = Philtre.filter dataset: Personage, name: 'Dylan', age_gt: 21, age_lt: 67
# File lib/philtre.rb, line 35
def self.filter( dataset: nil, with: {}, **kwargs )
  new(with.merge kwargs).apply(dataset)
end
grind( dataset: nil, with: {}, **kwargs ) click to toggle source

Create a grinder with the parameters, and use it on the dataset. Return the result.

dataset should have placeholders, otherwise calling this method just warms your cpu.

# File lib/philtre.rb, line 44
def self.grind( dataset: nil, with: {}, **kwargs )
  filter = new(with.merge kwargs)
  Philtre::Grinder.new(filter).transform(dataset)
end
new( *filter_parameters, &blk ) click to toggle source

Just a factory method that calls Filter.new

philtre = Philtre.new params[:filter]
# File lib/philtre.rb, line 18
def self.new( *filter_parameters, &blk )
  Filter.new *filter_parameters, &blk
end