Class: Returnly::Discounts::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/returnly/discounts/order.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#adjustmentObject (readonly)

Returns the value of attribute adjustment.



4
5
6
# File 'lib/returnly/discounts/order.rb', line 4

def adjustment
  @adjustment
end

#orderObject (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