Class: Returnly::Discounts::Order
- Inherits:
-
Object
- Object
- Returnly::Discounts::Order
- Defined in:
- lib/returnly/discounts/order.rb
Instance Attribute Summary collapse
-
#adjustment ⇒ Object
readonly
Returns the value of attribute adjustment.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
- #discount_amount(line_item, units = 0) ⇒ Object
-
#initialize(order, adjustment) ⇒ Order
constructor
A new instance of Order.
Constructor Details
#initialize(order, adjustment) ⇒ Order
Returns a new instance of Order.
6 7 8 9 |
# File 'lib/returnly/discounts/order.rb', line 6 def initialize(order, adjustment) @adjustment = adjustment @order = order end |
Instance Attribute Details
#adjustment ⇒ Object (readonly)
Returns the value of attribute adjustment.
4 5 6 |
# File 'lib/returnly/discounts/order.rb', line 4 def adjustment @adjustment end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'lib/returnly/discounts/order.rb', line 4 def order @order end |
Instance Method Details
#discount_amount(line_item, units = 0) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/returnly/discounts/order.rb', line 11 def discount_amount(line_item, units = 0) return 0.0 if units <= 0 units = line_item.quantity if units > line_item.quantity (adjustment.amount * price_percent(line_item) / 100) * weight_of(line_item, units.to_d) end |