1
0

54 lines
949 B
Ruby

# frozen_string_literal: true
module PlanetExpress
class Shipment
attr_reader :date, :shipping_option, :discounts
def initialize(date, shipping_option)
@date = date
@shipping_option = shipping_option
@discounts = []
end
def month
date.begin_of_month
end
def price_with_discounts
shipping_option.price_in_cents - total_discount_amount
end
def total_discount_amount
discounts.map(&:amount).sum
end
def lp_provider?
shipping_option.lp_provider?
end
def s_shipment?
shipping_option.s_shipment?
end
def l_shipment?
shipping_option.l_shipment?
end
def provider
shipping_option.provider
end
def if_valid
yield self
end
def add_discount(discount)
discounts.push(discount)
end
def inspect
"#{self.class.name} [#{date} #{shipping_option.inspect} #{discounts}]"
end
end
end