Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c35757f
Created movie class with attributes and created starring(actor_name) …
Sabineth17 Sep 4, 2018
712ed68
Started contain date_range method
Sabineth17 Sep 5, 2018
aadb210
Successfully passed all tests for contains method
Sabineth17 Sep 5, 2018
519749f
created and successfully passed method nights to tally number nights
Sabineth17 Sep 5, 2018
f062626
Completed overlaps methods and tests
Sabineth17 Sep 6, 2018
651442d
Trying to refactor an adjust my rental initialize methods
Sabineth17 Sep 6, 2018
bf943a9
Trying to update my methods for Rental so the test can pass
Sabineth17 Sep 7, 2018
06db929
Wave 2 Rental initialization and cost methods completed
Sabineth17 Sep 7, 2018
d6d83ef
Created a self.load_movies method, still need to instantiate
Sabineth17 Sep 7, 2018
e4528e1
Add coverage directory to .gitignore file
Sabineth17 Sep 7, 2018
8bb4291
added Simplecov in spec files
Sabineth17 Sep 7, 2018
2a143a8
finalized self.load_movies and passed all instantialization tests
Sabineth17 Sep 7, 2018
f58479f
Working through available movies method
Sabineth17 Sep 9, 2018
4908fae
Test0001 of movies available passed. Test002 failed because it requir…
Sabineth17 Sep 9, 2018
a665208
Updated code and test code to 'hide' rent_movie method. Movie availab…
Sabineth17 Sep 10, 2018
d2275d4
Tests and Codes to be updated this afternoon
Sabineth17 Sep 10, 2018
704b131
rent_movie methods are almost completed
Sabineth17 Sep 11, 2018
7bbb903
All tests for rent_movies are written, need to ccomplete codes for re…
Sabineth17 Sep 11, 2018
e3167e4
Still working on completing available_movies and rent_movies methods.…
Sabineth17 Sep 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ build-iPhoneSimulator/

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
coverage
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ A `Rental` will contain an `initialize` method and the following attributes:
* movie: The movie being rented
* customer: The name of the customer making the rental

A `Rental` will have the follwing methods:
A `Rental` will have the following methods:

* `cost`: This method will return the cost of the rental. A movie rental will cost $3.0 per night. The customer is **not** charged for the day the movie is checked in. So a movie checked out on August 8th and checked in August 10th would cost $3.00 * 2 days = $6.00

Expand All @@ -102,7 +102,7 @@ This class will contain an `initialize` method and the following attributes:
* movies: The list of movies available in the system
* rentals: A list of all the rentals which have occurred.

The `RentalManager` will be able to perform the following actions (methods):
The `MovieReserver` will be able to perform the following actions (methods):

* `self.load_movies`: This method will open the csv file `movies.csv` and read in the movies and return an array of the given movies. Note the actors are separated by the `:` character. You will need to break up that field.
- The `initialize` method should use `self.load_movies` to read in the movie list for the application
Expand All @@ -114,4 +114,4 @@ The `RentalManager` will be able to perform the following actions (methods):
## Optional Enhancements

You can add the following methods along with tests to further enhance this project:
- movies_staring(actor_name, date_range): This method will list all movies available in the given date range and with the provied actor.
- movies_staring(actor_name, date_range): This method will list all movies available in the given date range and with the provided actor.
39 changes: 39 additions & 0 deletions lib/date_range.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
require 'time'
require_relative 'movie_reserver'

module GreenBox
# When a movie is being rented you need to understand when that rental occurs. To represent that interval of time, you will create a `DateRange` class.
class DateRange
attr_reader :start_date , :end_date, :nights

def initialize(start_date, end_date)
@start_date = start_date
@end_date = end_date

if start_date > end_date
raise ArgumentError.new "The end date is before the start date"
end
end

# `contains(date)` - This method returns true if the date occurs on or after the start date and before the end date.
def contains(date)
if (date >= @start_date) && (date < @end_date)
return true
else
date < @start_date || date >= @end_date
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this 2nd conditional since if it's not inside you can return false.

if (date >= @start_date) && (date < @end_date)
        return true
      else
        return false
end

return false
end
end


# `overlaps(other_date_range)` - This method takes another date range as a parameter and returns `true` if the date ranges overlap.
def overlaps(other_date_range)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if contains(other_date_range.start_date) || contains(other_date_range.end_date)
true
elsif other_date_range.contains(@start_date) && other_date_range.contains(@end_date)
true
else
false
end
end

# `nights` - This method will return the number of nights included in the given `DateRange.
def nights
count = (@end_date - @start_date)/(60*60*24)
return count
end
end
end
23 changes: 23 additions & 0 deletions lib/movie.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
require 'csv'

module GreenBox
#A 'movie class' represents a film in our system database
class Movie
attr_reader :id, :title, :publisher, :actors

def initialize(id,title,publisher, actors:[])
@id = id
@title = title
@publisher = publisher
@actors = actors
end

movie = GreenBox::Movie.new(4,'Happiness','Fox',actors:['Denzel Washington', 'LL Cool J'])
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can take this line out


#This method will return true if the given actor does appear in the movie.

def stars_actor(actor_name)
actors.each do |actor|
if actor_name == actor
return true
end
end
return false
end
end
end
114 changes: 114 additions & 0 deletions lib/movie_reserver.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,121 @@
require 'csv'
require 'pry'
require_relative 'date_range'
require_relative 'movie'
require_relative 'rental'


module GreenBox
class MovieReserver
attr_accessor :movies, :rentals, :date_range
# :reserver, :date_range

def initialize
@movies = MovieReserver.load_movies
@rentals = []
@date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09'))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This @date_range is unnecessary since there isn't one daterange needed by the system. Instead each Rental will have it's own DateRange

end

# `self.load_movies`: This method will open the csv file `movies.csv` and read in the movies and return an array of the given movies. Note the actors are separated by the `:` character. You will need to break up that field.
def self.load_movies
showtime_movies = []

CSV.read('data/movies.csv', headers: false).each do |line|
movie_id = line[0].to_i
title = line[1]
publisher = line[2]
all_actors = line[3]
actors_names = all_actors.split(':')
actors = {actors: actors_names}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also make this:

actors = actors_names

And just use an array instead of a has containing one array.


showtime_movies << GreenBox::Movie.new(movie_id, title, publisher, actors)
end
return showtime_movies
end


# `available_movies(date_range)`: This method will take a `DateRange` instance and return a list of
# movies available (not rented yet) in that range.
def available_movies(date_range)

# @movies = available_movies
# If @rentals = [] - is empty,
if @rentals.empty?
# then all the movies are available
return @movies
else
# @movies is a MovieReserver object that contains movies.
available_movies = []
@movies.each do |movie|
if @rentals.date_range == date_range
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is not quite right. @rentals is an array and so doesn't have a date_range attribute.
Instead you should:

  1. make a copy of the movies list
  2. then loop through your rentals array and remove any movies who have a rental that conflicts.

You can look up the select method to find movies that don't have a given ID or object id.

available_movies << movie
end
end
return @rentals
end
end
#PSEUDOCODE
# If there is a movie in rentals
##### Want to check what movies are in rentals
# that fall into that date date_range
# and remove that movie only
# will need to use a data structure to only use the ID that are in the date_range
#use data structure to store those and match
# them with the ones in the movie list
#

# if @rentals.length > 0
# @rentals.each do |movies|
# date_range
# if @movies.include(date_range)
# available_movies = @movies.delete(date_range)
# end

# @rentals.each do |movie|
# movie.id
# if @movies.include(movie.id)
# available_movies = @movies.delete(movie.id)
# end

# end

# end

# * `rent_movie(movie_title, date_range, customer_name)`: This method will attempt to reserve a movie with the given title for the given date range. If the movie is not available in that range the method should raise a `StandardError`.

def rent_movie(movie_title, date_range, customer_name)
@movies.each do |movie|
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As your test shows, this isn't working because it always rents a movie as long as the movie is in the inventory.

If I can make a suggestion:

  1. See if the list of available_movies has this movie title, you can use .each or find_by to do so.
  2. If so, you can create a rental,
  3. add it to the list
  4. return the rental

if movie.title == movie_title
@rentals << movie
return @rentals
end
end
# If we finish the loop and nothing is found, raise an error here.
raise ArgumentError.new("No movies found!")
end
end

end



# available_movies = @rentals.map do |movie|
# if @rentals.date_range.contains(movie.id)
# return available_movies
# else
# @rentals << movie
# end
# end
# movies not rented yet = showtime_movies
# movies rented = rentals
#
# available_movies << GreenBox::Rental.new(movie,date_range)
#
# available_movies = MovieReserver.load_movies
#
# @rentals = available_movies.each do |date_range|
# if @rentals.date_range <= 0
# @rentals << movie
# end
# end
# return available_movies
22 changes: 22 additions & 0 deletions lib/rental.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
require_relative 'date_range'
require 'time'
require_relative 'movie'


module GreenBox
# A `Rental` represents a movie rental in the system.
class Rental
attr_accessor :movie, :date_range, :customer

def initialize(movie, date_range, customer)
if date_range.nights <= 0
raise ArgumentError.new "This is an illegal date range"
end
@movie = movie
@date_range = date_range
# * customer: The name of the customer making the rental
@customer = customer
end

# * `cost`: This method will return the cost of the rental. A movie rental will cost $3.0 per night. The customer is **not** charged for the day the movie is checked in. So a movie checked out on August 8th and checked in August 10th would cost $3.00 * 2 days = $6.00
def cost
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

rent = @date_range.nights
cost = rent * 3.0
return cost.round(2)
end
end
end
2 changes: 1 addition & 1 deletion specs/date_range_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_relative 'spec_helper'


xdescribe 'GreenBox::DateRange' do
describe 'GreenBox::DateRange' do

describe 'initialization' do
it 'can be created' do
Expand Down
Loading