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

Commit

Permalink
add Rental#charge method. Only public method necessary to calculate w…
Browse files Browse the repository at this point in the history
…hat to charge for a rental
  • Loading branch information
edgenard committed Jul 30, 2018
1 parent 5f27122 commit e841b02
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions a_first_example/first_example.rb
Expand Up @@ -20,6 +20,12 @@ def initialize(movie, days_rented)
@movie, @days_rented = movie, days_rented
end

def charge
base_charge + extra_charge

This comment has been minimized.

Copy link
@medwards1771

medwards1771 Jul 31, 2018

Contributor

Here's another move, but tell me: how do you distinguish public methods from private?

end

private

def base_charge
case movie.price_code
when Movie::REGULAR
Expand Down Expand Up @@ -69,7 +75,7 @@ def statement
@rentals.each do |rental|
this_amount = 0

this_amount += charge_for_rental(rental)
this_amount += rental.charge

frequent_renter_points += points_for_rental(rental)

Expand All @@ -83,17 +89,6 @@ def statement
result
end

def charge_for_rental(rental)
case rental.movie.price_code
when Movie::REGULAR
rental.base_charge + rental.extra_charge
when Movie::NEW_RELEASE
rental.base_charge + rental.extra_charge
when Movie::CHILDRENS
rental.base_charge + rental.extra_charge
end
end

def points_for_rental(rental)
case rental.movie.price_code
when Movie::CHILDRENS, Movie::REGULAR
Expand Down

0 comments on commit e841b02

Please sign in to comment.