class ContextFilters::Filters::PriorityFilters

list of filters sorted by priorities

Attributes

priorities[R]

@return [Array] list of priorities this object was initialized with

Public Class Methods

new(priorities = nil) click to toggle source

initializes priorities and coresponding list of filters @param priorities [Array|Object] a list of priorities to order filters

# File lib/context-filters/filters/priority_filters.rb, line 19
def initialize(priorities = nil)
  @priorities = [priorities].flatten.freeze
  @filters_array = @priorities.product([Filters.new])
end

Public Instance Methods

each(&block) click to toggle source

iterate over filters ordered by priority @yield [priority,filters] the next filters from sorted array @yieldparam priority [Object] the priority @yieldparam filters [Filters] the filters for priority

# File lib/context-filters/filters/priority_filters.rb, line 45
def each(&block)
  to_a.each(&block) unless empty?
end
empty?() click to toggle source

check if all of the filters are empty return [Bolean] true if all filters are empty

# File lib/context-filters/filters/priority_filters.rb, line 51
def empty?
  @filters_array.map(&:last).all?(&:empty?)
end
store(priority, options = nil, &block) click to toggle source

adds a priority filter

@param priority [Object] anything that was part of priorities array @param options [Object] forwarded to Filters.store @param block [Proc] forwarded to Filters.store @raise [KeyError] when priority not matching priorities is used

# File lib/context-filters/filters/priority_filters.rb, line 30
def store(priority, options = nil, &block)
  found = @filters_array.assoc(priority)
  raise KeyError if found.nil?
  found.last.store(options, &block)
end
to_a() click to toggle source

list of filters sorted by priorities

# File lib/context-filters/filters/priority_filters.rb, line 37
def to_a
  @filters_array
end