-
Notifications
You must be signed in to change notification settings - Fork 0
/
customer.rb
46 lines (39 loc) · 1.13 KB
/
customer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Customer
attr_reader :name
def initialize(name)
@name = name
@rentals = []
end
def add_rental(arg)
@rentals << arg
end
def html_statement
result = "<h1>Rentals for <em>#{@name}</em></h1><p>\n"
@rentals.each do |element|
result += "\t" + element.movie.title + ": " + element.charge.to_s + "<br>\n"
end
# フッター行を追加
result += "You owe <em>#{total_charge}</em><p>\n"
result += "On this rental you earned " +
"<em>#{total_frequent_renter_points}</em> " +
"frequent renter points<p>"
result
end
def statement
result = "Rental Record for #{@name}\n"
@rentals.each do |element|
result += "\t" + element.movie.title + "\t" + element.charge.to_s + "\n"
end
# フッター行を追加
result += "Amount owed is #{total_charge}\n"
result += "You earned #{total_frequent_renter_points} frequent renter points"
result
end
private
def total_charge
@rentals.inject(0) {|sum, rental| sum + rental.charge }
end
def total_frequent_renter_points
@rentals.inject(0) {|sum, rental| sum + rental.frequent_renter_points }
end
end