Class: Filternator::Filter
- Inherits:
-
Object
- Object
- Filternator::Filter
- Defined in:
- lib/filternator/filter.rb
Instance Attribute Summary collapse
-
#all_filters ⇒ Object
readonly
Returns the value of attribute all_filters.
-
#default_filter ⇒ Object
readonly
Returns the value of attribute default_filter.
-
#presenter ⇒ Object
readonly
Returns the value of attribute presenter.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#scope_name ⇒ Object
readonly
Returns the value of attribute scope_name.
Instance Method Summary collapse
- #apply(params) ⇒ Object
-
#initialize(options = {}) ⇒ Filter
constructor
A new instance of Filter.
- #stats ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Filter
Returns a new instance of Filter.
6 7 8 9 10 11 12 |
# File 'lib/filternator/filter.rb', line 6 def initialize( = {}) @scope = .fetch(:scope) @scope_name = .fetch(:scope_name) { derive_scope_name } @presenter = .fetch(:presenter) { null_presenter } @all_filters = .fetch(:all_filters) { scope.all_filters } @default_filter = .fetch(:default_filter) { "all" } end |
Instance Attribute Details
#all_filters ⇒ Object (readonly)
Returns the value of attribute all_filters.
4 5 6 |
# File 'lib/filternator/filter.rb', line 4 def all_filters @all_filters end |
#default_filter ⇒ Object (readonly)
Returns the value of attribute default_filter.
4 5 6 |
# File 'lib/filternator/filter.rb', line 4 def default_filter @default_filter end |
#presenter ⇒ Object (readonly)
Returns the value of attribute presenter.
4 5 6 |
# File 'lib/filternator/filter.rb', line 4 def presenter @presenter end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
4 5 6 |
# File 'lib/filternator/filter.rb', line 4 def scope @scope end |
#scope_name ⇒ Object (readonly)
Returns the value of attribute scope_name.
4 5 6 |
# File 'lib/filternator/filter.rb', line 4 def scope_name @scope_name end |
Instance Method Details
#apply(params) ⇒ Object
23 24 25 |
# File 'lib/filternator/filter.rb', line 23 def apply(params) ApplyFilter.new(self, params) end |
#stats ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/filternator/filter.rb', line 14 def stats pairs = all_filters.map { |filter| result = apply(filter: filter).count result = result.values.inject(:+) if result.is_a?(Hash) # ActiveRecord `group by` fix [ filter, result ] } Hash[pairs] end |