Class: Spree::Filters::QuantifiedPriceRangePresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/spree/filters/quantified_price_range_presenter.rb

Constant Summary collapse

ALLOWED_QUANTIFIERS =
[
  :less_than,
  :more_than
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(price:, quantifier:) ⇒ QuantifiedPriceRangePresenter

Returns a new instance of QuantifiedPriceRangePresenter.



9
10
11
12
13
14
15
16
# File 'app/presenters/spree/filters/quantified_price_range_presenter.rb', line 9

def initialize(price:, quantifier:)
  if ALLOWED_QUANTIFIERS.exclude?(quantifier.to_sym)
    raise ArgumentError, "quantifier must be one of: #{ALLOWED_QUANTIFIERS.join(', ')}"
  end

  @price = price
  @quantifier = quantifier.to_sym
end

Instance Method Details

#to_paramObject



18
19
20
21
22
23
24
25
# File 'app/presenters/spree/filters/quantified_price_range_presenter.rb', line 18

def to_param
  case quantifier
  when :less_than
    less_than_param
  when :more_than
    more_than_param
  end
end

#to_sObject



27
28
29
# File 'app/presenters/spree/filters/quantified_price_range_presenter.rb', line 27

def to_s
  "#{I18n.t("activerecord.attributes.spree/product.#{quantifier}")} #{price}"
end