Class: AhoyCaptain::ComparisonLinkComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
CompareMode, RangeOptions, Rangeable
Defined in:
app/components/ahoy_captain/comparison_link_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Rangeable

#period

Methods included from CompareMode

#compare_mode?, #comparison_mode, included

Constructor Details

#initialize(title: "", classes: "btn btn-sm btn-base-100 no-underline hover:bg-base-100") ⇒ ComparisonLinkComponent

Returns a new instance of ComparisonLinkComponent.



12
13
14
# File 'app/components/ahoy_captain/comparison_link_component.rb', line 12

def initialize(title: "", classes: "btn btn-sm btn-base-100 no-underline hover:bg-base-100")
  @classes = classes
end

Instance Attribute Details

#classesObject (readonly)

Returns the value of attribute classes.



11
12
13
# File 'app/components/ahoy_captain/comparison_link_component.rb', line 11

def classes
  @classes
end

#titleObject (readonly)

cheating



17
18
19
# File 'app/components/ahoy_captain/comparison_link_component.rb', line 17

def title
  @title
end

Instance Method Details

#options_for_optionObject



27
28
29
30
31
32
33
34
35
# File 'app/components/ahoy_captain/comparison_link_component.rb', line 27

def options_for_option
  [
    (link_to "Custom period", "javascript:customComparisonModal.showModal()", class: selected(:custom)),
    (link_to "Year-over-year", AhoyCaptain::Engine.routes.url_helpers.root_path(**helpers.search_params.merge(comparison: :year)), class: selected(:year)),
    (link_to "Previous period", AhoyCaptain::Engine.routes.url_helpers.root_path(**helpers.search_params.merge(comparison: :previous)), class: selected(:previous, :true)),
    (link_to "Disable Comparison", AhoyCaptain::Engine.routes.url_helpers.root_path(**helpers.search_params.merge(comparison: false))),

  ].reverse.join.html_safe
end

#render?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/components/ahoy_captain/comparison_link_component.rb', line 23

def render?
  comparison_mode.enabled?
end