Class: Spree::Filters::PriceRangePresenter

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min_price:, max_price:) ⇒ PriceRangePresenter

Returns a new instance of PriceRangePresenter.



13
14
15
16
# File 'app/presenters/spree/filters/price_range_presenter.rb', line 13

def initialize(min_price:, max_price:)
  @min_price = min_price
  @max_price = max_price
end

Instance Attribute Details

#max_priceObject (readonly)

Returns the value of attribute max_price.



18
19
20
# File 'app/presenters/spree/filters/price_range_presenter.rb', line 18

def max_price
  @max_price
end

#min_priceObject (readonly)

Returns the value of attribute min_price.



18
19
20
# File 'app/presenters/spree/filters/price_range_presenter.rb', line 18

def min_price
  @min_price
end

Class Method Details

.from_param(param, currency:) ⇒ Object



4
5
6
7
8
9
10
11
# File 'app/presenters/spree/filters/price_range_presenter.rb', line 4

def self.from_param(param, currency:)
  prices = param.split('-')

  new(
    min_price: PricePresenter.new(amount: prices.first, currency: currency),
    max_price: PricePresenter.new(amount: prices.last, currency: currency)
  )
end

Instance Method Details

#to_paramObject



20
21
22
# File 'app/presenters/spree/filters/price_range_presenter.rb', line 20

def to_param
  "#{min_price.to_i}-#{max_price.to_i}"
end

#to_sObject



24
25
26
# File 'app/presenters/spree/filters/price_range_presenter.rb', line 24

def to_s
  "#{min_price} - #{max_price}"
end