Skip to content
This repository has been archived by the owner on Apr 24, 2019. It is now read-only.

Commit

Permalink
move base_charge to rental
Browse files Browse the repository at this point in the history
  • Loading branch information
edgenard committed Jul 30, 2018
1 parent 8974cf3 commit 8bca504
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions a_first_example/first_example.rb
Expand Up @@ -19,6 +19,17 @@ class Rental
def initialize(movie, days_rented)
@movie, @days_rented = movie, days_rented
end

def base_charge
case movie.price_code
when Movie::REGULAR
2
when Movie::CHILDRENS
1.5
when Movie::NEW_RELEASE
days_rented * 3
end
end
end

class Customer
Expand Down Expand Up @@ -56,22 +67,11 @@ def statement
def charge_for_rental(rental)
case rental.movie.price_code
when Movie::REGULAR
base_charge_for_rental(rental) + extra_charge_for_rental(rental)
rental.base_charge + extra_charge_for_rental(rental)
when Movie::NEW_RELEASE
base_charge_for_rental(rental) + extra_charge_for_rental(rental)
rental.base_charge + extra_charge_for_rental(rental)
when Movie::CHILDRENS
base_charge_for_rental(rental) + extra_charge_for_rental(rental)
end
end

def base_charge_for_rental(rental)
case rental.movie.price_code
when Movie::REGULAR
2
when Movie::CHILDRENS
1.5
when Movie::NEW_RELEASE
rental.days_rented * 3
rental.base_charge + extra_charge_for_rental(rental)
end
end

Expand Down

0 comments on commit 8bca504

Please sign in to comment.