Class: AhoyCaptain::FilterConfiguration::FilterCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/ahoy_captain/filter_configuration/filter_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(label) ⇒ FilterCollection

Returns a new instance of FilterCollection.



4
5
6
7
# File 'lib/ahoy_captain/filter_configuration/filter_collection.rb', line 4

def initialize(label)
  @label = label
  @registry = []
end

Instance Method Details

#[](name) ⇒ Object



39
40
41
# File 'lib/ahoy_captain/filter_configuration/filter_collection.rb', line 39

def [](name)
  find(name)
end

#delete(name) ⇒ Object



31
32
33
# File 'lib/ahoy_captain/filter_configuration/filter_collection.rb', line 31

def delete(name)
  @registry.delete_if { |filter| filter.column == name }
end

#each(&block) ⇒ Object



19
20
21
# File 'lib/ahoy_captain/filter_configuration/filter_collection.rb', line 19

def each(&block)
  @registry.each(&block)
end

#filter(label:, column:, url:, predicates: [:in, :not_in], multiple: true, position: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/ahoy_captain/filter_configuration/filter_collection.rb', line 9

def filter(label:, column:, url:, predicates: [:in, :not_in], multiple: true, position: nil)
  position ||= @registry.size
  if item = find(column)
    @registry.delete(item)
  end

  @registry << FilterConfiguration::Filter.new(label: label, column: column, url: url, predicates: predicates, multiple: multiple, position: position)
  @registry = @registry.sort_by { |filter| filter.position }
end

#filtersObject



35
36
37
# File 'lib/ahoy_captain/filter_configuration/filter_collection.rb', line 35

def filters
  @registry
end

#find(column) ⇒ Object



27
28
29
# File 'lib/ahoy_captain/filter_configuration/filter_collection.rb', line 27

def find(column)
  @registry.find { |filter| filter.column == column.to_sym }
end

#include?(name) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ahoy_captain/filter_configuration/filter_collection.rb', line 43

def include?(name)
  find(name).present?
end


23
24
25
# File 'lib/ahoy_captain/filter_configuration/filter_collection.rb', line 23

def modal_name
  "#{@label.parameterize.underscore}Modal"
end