Class: ItemBuilderMwh::Modes::Price::SalePricePolicy
- Inherits:
-
Object
- Object
- ItemBuilderMwh::Modes::Price::SalePricePolicy
- Defined in:
- lib/item_builder_mwh/modes/price/sale_price_policy.rb
Instance Attribute Summary collapse
-
#listing ⇒ Object
readonly
Returns the value of attribute listing.
Instance Method Summary collapse
-
#initialize(args) ⇒ SalePricePolicy
constructor
A new instance of SalePricePolicy.
- #on_sale? ⇒ Boolean
- #sale_date? ⇒ Boolean
- #sale_price ⇒ Object
- #sale_price? ⇒ Boolean
Constructor Details
#initialize(args) ⇒ SalePricePolicy
Returns a new instance of SalePricePolicy.
11 12 13 |
# File 'lib/item_builder_mwh/modes/price/sale_price_policy.rb', line 11 def initialize(args) @listing = args.fetch(:listing) end |
Instance Attribute Details
#listing ⇒ Object (readonly)
Returns the value of attribute listing.
10 11 12 |
# File 'lib/item_builder_mwh/modes/price/sale_price_policy.rb', line 10 def listing @listing end |
Instance Method Details
#on_sale? ⇒ Boolean
34 35 36 37 38 39 40 |
# File 'lib/item_builder_mwh/modes/price/sale_price_policy.rb', line 34 def on_sale? return false unless sale_price? sale_start_at = listing.sale_start_at || DateTime.now sale_end_at = listing.sale_end_at || DateTime.now + 1_000_000.years sale_start_at <= DateTime.now && sale_end_at >= DateTime.now end |
#sale_date? ⇒ Boolean
30 31 32 |
# File 'lib/item_builder_mwh/modes/price/sale_price_policy.rb', line 30 def sale_date? listing.sale_start_at && listing.sale_end_at end |
#sale_price ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/item_builder_mwh/modes/price/sale_price_policy.rb', line 15 def sale_price # has sale price but no sale date defined # then push sale price immediately # assuming it starts today and no end date specified return listing.sale_price if sale_price? && !sale_date? # has sale price and today is on sale then push sale price immediately listing.sale_price if sale_price? && on_sale? # don't push / don't return anything if 2 rules above unfulfilled end |
#sale_price? ⇒ Boolean
26 27 28 |
# File 'lib/item_builder_mwh/modes/price/sale_price_policy.rb', line 26 def sale_price? listing.sale_price end |