Class: ClassyFilter::Base
- Inherits:
-
Object
- Object
- ClassyFilter::Base
- Extended by:
- ClassMethods, Forwardable
- Defined in:
- lib/classy_filter.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #call(dataset) ⇒ Object
-
#initialize(params) ⇒ Base
constructor
A new instance of Base.
Methods included from ClassMethods
coercion, coercions_module, filter_field, predicate, predicates_module
Constructor Details
#initialize(params) ⇒ Base
Returns a new instance of Base.
16 17 18 |
# File 'lib/classy_filter.rb', line 16 def initialize(params) @params = params.transform_keys(&:to_s) end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
14 15 16 |
# File 'lib/classy_filter.rb', line 14 def params @params end |
Instance Method Details
#call(dataset) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/classy_filter.rb', line 20 def call(dataset) filter_fields.reduce(dataset) do |ds, (value, field)| value = coercions_module.coerce(value, field.coercion) if field.coercion attribute = field.attribute || field.param_name predicates_module.send(field.predicate, ds, attribute, value) end end |