Skip to content

Instantly share code, notes, and snippets.

@nmondollot
Created June 19, 2014 10:24
Show Gist options
  • Save nmondollot/b8317096f59101d7ccc5 to your computer and use it in GitHub Desktop.
Save nmondollot/b8317096f59101d7ccc5 to your computer and use it in GitHub Desktop.
module Drivy::Pricing
+ class ChargesCalculator
+ attr_reader :rental_parameters, :rental_price, :cdw_price, :owner_charges, :driver_charges
+
+ delegate :drivy_comm, :assistance_fee, :insurance_fee, to: :owner_charges
+ delegate :rental_price, :cdw_price, to: :driver_charges
+
+ def initialize(rental_parameters, rental_price, cdw_enabled, car)
+ @rental_parameters = rental_parameters
+ @cdw_price = cdw_enabled ? CdwPrice.new(rental_parameters) : NullCdwPrice.new
+ @rental_price = rental_price
+ @car = car
+
+ @owner_charges = Drivy::Pricing::OwnerCharges.new(@rental_price.total, @rental_parameters.length, tall_vehicle: @car.tall?, recent_vehicle: @car.recent?(@rental_parameters.starts_at))
+ @driver_charges = Drivy::Pricing::DriverCharges.new(@rental_price, @cdw_price)
+ end
+
+ def total_owner
+ @owner_charges.total
+ end
+
+ def total_driver
+ @driver_charges.total
+ end
+ end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment