summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/customer.rb (renamed from lib/refactoring.rb)28
-rw-r--r--lib/movie.rb12
-rw-r--r--lib/rental.rb7
3 files changed, 23 insertions, 24 deletions
diff --git a/lib/refactoring.rb b/lib/customer.rb
index 52bfafb..c2ce3b0 100644
--- a/lib/refactoring.rb
+++ b/lib/customer.rb
@@ -1,24 +1,3 @@
-class Movie
- REGULAR = 0
- NEW_RELEASE = 1
- CHILDRENS = 2
-
- attr_reader :title
- attr_accessor :price_code
-
- def initialize(title, price_code)
- @title, @price_code = title, price_code
- end
-end
-
-class Rental
- attr_reader :movie, :days_rented
-
- def initialize(movie, days_rented)
- @movie, @days_rented = movie, days_rented
- end
-end
-
class Customer
attr_reader :name
@@ -30,7 +9,7 @@ class Customer
def add_rental(arg)
@rentals << arg
end
-
+
def statement
total_amount, frequent_renter_points = 0, 0
result = "Rental Record for #{@name}\n"
@@ -53,7 +32,7 @@ class Customer
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
+ frequent_renter_points += 1
end
# show figures for this rental
result += "\t" + element.movie.title + "\t" + this_amount.to_s + "\n"
@@ -63,4 +42,5 @@ class Customer
result += "Amount owed is #{total_amount}\n"
result += "You earned #{frequent_renter_points} frequent renter points"
result
- end \ No newline at end of file
+ end
+end
diff --git a/lib/movie.rb b/lib/movie.rb
new file mode 100644
index 0000000..a085d46
--- /dev/null
+++ b/lib/movie.rb
@@ -0,0 +1,12 @@
+class Movie
+ REGULAR = 0
+ NEW_RELEASE = 1
+ CHILDRENS = 2
+
+ attr_reader :title
+ attr_accessor :price_code
+
+ def initialize(title, price_code)
+ @title, @price_code = title, price_code
+ end
+end
diff --git a/lib/rental.rb b/lib/rental.rb
new file mode 100644
index 0000000..3409359
--- /dev/null
+++ b/lib/rental.rb
@@ -0,0 +1,7 @@
+class Rental
+ attr_reader :movie, :days_rented
+
+ def initialize(movie, days_rented)
+ @movie, @days_rented = movie, days_rented
+ end
+end