Class: SourceMonitor::SourcesFilterPresenter
- Inherits:
-
Object
- Object
- SourceMonitor::SourcesFilterPresenter
- Defined in:
- app/presenters/source_monitor/sources_filter_presenter.rb
Overview
Encapsulates filter state logic for the sources index view. Extracts filter detection, label generation, and active-filter tracking from the template into a testable object.
Constant Summary collapse
- DROPDOWN_FILTER_KEYS =
%w[ active_eq health_status_eq feed_format_eq scraper_adapter_eq scraping_enabled_eq avg_feed_words_lt ].freeze
Instance Attribute Summary collapse
-
#adapter_options ⇒ Object
readonly
Returns the value of attribute adapter_options.
-
#fetch_interval_filter ⇒ Object
readonly
Returns the value of attribute fetch_interval_filter.
-
#search_params ⇒ Object
readonly
Returns the value of attribute search_params.
-
#search_term ⇒ Object
readonly
Returns the value of attribute search_term.
Instance Method Summary collapse
-
#active_filter_keys ⇒ Object
Returns the subset of DROPDOWN_FILTER_KEYS that have present values.
-
#filter_labels ⇒ Object
Returns a hash mapping active filter keys to human-readable labels.
- #has_any_filter? ⇒ Boolean
-
#initialize(search_params:, search_term:, fetch_interval_filter:, adapter_options: []) ⇒ SourcesFilterPresenter
constructor
A new instance of SourcesFilterPresenter.
Constructor Details
#initialize(search_params:, search_term:, fetch_interval_filter:, adapter_options: []) ⇒ SourcesFilterPresenter
Returns a new instance of SourcesFilterPresenter.
23 24 25 26 27 28 |
# File 'app/presenters/source_monitor/sources_filter_presenter.rb', line 23 def initialize(search_params:, search_term:, fetch_interval_filter:, adapter_options: []) @search_params = search_params || {} @search_term = search_term.to_s @fetch_interval_filter = fetch_interval_filter @adapter_options = end |
Instance Attribute Details
#adapter_options ⇒ Object (readonly)
Returns the value of attribute adapter_options.
17 18 19 |
# File 'app/presenters/source_monitor/sources_filter_presenter.rb', line 17 def @adapter_options end |
#fetch_interval_filter ⇒ Object (readonly)
Returns the value of attribute fetch_interval_filter.
17 18 19 |
# File 'app/presenters/source_monitor/sources_filter_presenter.rb', line 17 def fetch_interval_filter @fetch_interval_filter end |
#search_params ⇒ Object (readonly)
Returns the value of attribute search_params.
17 18 19 |
# File 'app/presenters/source_monitor/sources_filter_presenter.rb', line 17 def search_params @search_params end |
#search_term ⇒ Object (readonly)
Returns the value of attribute search_term.
17 18 19 |
# File 'app/presenters/source_monitor/sources_filter_presenter.rb', line 17 def search_term @search_term end |
Instance Method Details
#active_filter_keys ⇒ Object
Returns the subset of DROPDOWN_FILTER_KEYS that have present values
35 36 37 |
# File 'app/presenters/source_monitor/sources_filter_presenter.rb', line 35 def active_filter_keys DROPDOWN_FILTER_KEYS.select { |k| @search_params[k].present? } end |
#filter_labels ⇒ Object
Returns a hash mapping active filter keys to human-readable labels
40 41 42 43 44 45 46 47 48 49 |
# File 'app/presenters/source_monitor/sources_filter_presenter.rb', line 40 def filter_labels { "active_eq" => status_label, "health_status_eq" => "Health: #{@search_params['health_status_eq']&.titleize}", "feed_format_eq" => "Format: #{@search_params['feed_format_eq']&.upcase}", "scraper_adapter_eq" => "Adapter: #{@search_params['scraper_adapter_eq']&.titleize}", "scraping_enabled_eq" => scraping_label, "avg_feed_words_lt" => "Avg Feed Words: < #{@search_params['avg_feed_words_lt']}" } end |
#has_any_filter? ⇒ Boolean
30 31 32 |
# File 'app/presenters/source_monitor/sources_filter_presenter.rb', line 30 def has_any_filter? @search_term.present? || @fetch_interval_filter.present? || active_filter_keys.any? end |