diff options
| author | mo khan <mo@mokhan.ca> | 2014-05-26 16:34:16 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-05-26 16:34:26 -0600 |
| commit | 7245619df4350c63d5d858c23efbe1057933a2e4 (patch) | |
| tree | a9d1246808a1d989ba92fa001b8a2ce69d139f5e /lib/customer.rb | |
| parent | 4ddbad3e6bd5a95ed4b9c680e93f39003612a61f (diff) | |
split apart files and add first spec.
Diffstat (limited to 'lib/customer.rb')
| -rw-r--r-- | lib/customer.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/customer.rb b/lib/customer.rb new file mode 100644 index 0000000..c2ce3b0 --- /dev/null +++ b/lib/customer.rb @@ -0,0 +1,46 @@ +class Customer + attr_reader :name + + def initialize(name) + @name = name + @rentals = [] + end + + def add_rental(arg) + @rentals << arg + end + + def statement + total_amount, frequent_renter_points = 0, 0 + result = "Rental Record for #{@name}\n" + @rentals.each do |element| + this_amount = 0 + + # determine amounts for each line + case element.movie.price_code + when Movie::REGULAR + this_amount += 2 + this_amount += (element.days_rented - 2) * 1.5 if element.days_rented > 2 + when Movie::NEW_RELEASE + this_amount += element.days_rented * 3 + when Movie::CHILDRENS + this_amount += 1.5 + this_amount += (element.days_rented - 3) * 1.5 if element.days_rented > 3 + end + + # add frequent renter points + frequent_renter_points += 1 + # add bonus for a two day new release rental + if element.movie.price_code == Movie.NEW_RELEASE && element.days_rented > 1 + frequent_renter_points += 1 + end + # show figures for this rental + result += "\t" + element.movie.title + "\t" + this_amount.to_s + "\n" + total_amount += this_amount + end + # add footer lines + result += "Amount owed is #{total_amount}\n" + result += "You earned #{frequent_renter_points} frequent renter points" + result + end +end |
