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

Commit

Permalink
extract #base_cost_of_movie concept
Browse files Browse the repository at this point in the history
  • Loading branch information
edgenard committed Jul 29, 2018
1 parent 2bb71cf commit a17cb0e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions a_first_example/first_example.rb
Expand Up @@ -42,12 +42,12 @@ def statement
# determine amounts for each line
case rental.movie.price_code
when Movie::REGULAR
this_amount += 2
this_amount += base_cost_of_movie(rental)

This comment has been minimized.

Copy link
@bbimeredithedwards

bbimeredithedwards Jul 31, 2018

For our listeners: what did you do here? Why move this into a method?

this_amount += (rental.days_rented - 2) * 1.5 if rental.days_rented > 2
when Movie::NEW_RELEASE
this_amount += rental.days_rented * 3
this_amount += base_cost_of_movie(rental) #base cost of movie
when Movie::CHILDRENS
this_amount += 1.5
this_amount += base_cost_of_movie(rental)
this_amount += (rental.days_rented - 3) * 1.5 if rental.days_rented > 3
end

Expand All @@ -65,4 +65,15 @@ def statement
result += "You earned #{frequent_renter_points.to_s} frequent renter points"
result
end

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

0 comments on commit a17cb0e

Please sign in to comment.