Sha256: 6fd7fbb2dd30122b1e2ef0a82e1595e7ea1709aae771e7dee79efe9e2c12f1df
Contents?: true
Size: 1.88 KB
Versions: 4
Compression:
Stored size: 1.88 KB
Contents
require 'philtre/filter.rb' require 'philtre/grinder.rb' # The high-level interface to Philtre. There are several ways # to use it: # 1. Philtre.new # philtre = Philtre.new name: 'Moustafa' # 1. Philtre # philtre = Philtre dataset: some_dataset, age_gt: 21 # philtre = Philtre dataset: some_dataset, with {age_gt: 21} # 1. 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} module Philtre # Just a factory method that calls Filter.new # # philtre = Philtre.new params[:filter] def self.new( *filter_parameters, &blk ) Filter.new *filter_parameters, &blk end # 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 # def self.filter( dataset: nil, with: {}, **kwargs ) new(with.merge kwargs).apply(dataset) end # 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. def self.grind( dataset: nil, with: {}, **kwargs ) filter = new(with.merge kwargs) Philtre::Grinder.new(filter).transform(dataset) end end require 'philtre/core_extensions.rb' # And this is the even higher-level smalltalk-style interface # # Philtre dataset: Personage, with: params[:filter] module Kernel private def Philtre( dataset: nil, with: {}, **kwargs ) Philtre.filter dataset: dataset, with: with, **kwargs end alias philtre Philtre end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
philtre-0.1.2 | lib/philtre.rb |
philtre-0.1.1 | lib/philtre.rb |
philtre-0.1.0 | lib/philtre.rb |
philtre-0.0.1 | lib/philtre.rb |