Class: SnFilterable::FilterCategoryComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
FilteredHelper
Defined in:
app/components/sn_filterable/filter_category_component.rb

Overview

Component for a filter’s category for the filters sidebar

Instance Method Summary collapse

Methods included from FilteredHelper

#add_filter_url, #clear_all_url, #clear_filter_url, #clear_sort_url, #filtered_form_inputs, #filtered_form_with, #filtered_paginate, #remove_filter_url, #remove_sub_filter_url, #set_filter_url, #sort_url, #table_header_sort_link

Constructor Details

#initialize(filtered:, filter:) ⇒ FilterCategoryComponent

Returns a new instance of FilterCategoryComponent.

Parameters:

  • filtered (Filtered)

    The filtered instance

  • filters (Hash)

    The filter’s info



9
10
11
12
# File 'app/components/sn_filterable/filter_category_component.rb', line 9

def initialize(filtered:, filter:)
  @filtered = filtered
  @filter = filter
end

Instance Method Details

#sub_filter_checked?(sub_filter) ⇒ Boolean

Returns if this sub filter should be checked, denoting that the filter is active

Parameters:

  • sub_filter (String)

    The sub filter’s info

Returns:

  • (Boolean)

    True if the filter should be checked



18
19
20
21
22
23
24
25
26
27
28
# File 'app/components/sn_filterable/filter_category_component.rb', line 18

def sub_filter_checked?(sub_filter)
  filter_query_value = @filtered.queries.dig("filter", @filter[:filter_name])

  return false if filter_query_value.blank?

  if filter_query_value.is_a?(Array)
    filter_query_value.include?((sub_filter[:value]).to_s)
  else
    filter_query_value == (sub_filter[:value]).to_s
  end
end