summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Peasley <stephenpeasley@hotmail.com>2013-10-05 08:45:44 -0600
committerStephen Peasley <stephenpeasley@hotmail.com>2013-10-05 08:45:44 -0600
commit967483d527e9f1f1a9cb321c686b546ac6c1f650 (patch)
tree17b11b7c763f4cdb326586b69023464087eb4864
parent3f47702bcea109aa3ebcb5fe0183c7d3fc559db1 (diff)
implement each in different ways and do a bit of cleanup.
-rw-r--r--lib/helpers.rb10
-rw-r--r--lib/movie_library.rb58
-rw-r--r--lib/movielibrary.rb28
-rw-r--r--spec/lesson_three/movie_library_spec.rb10
-rw-r--r--spec/spec_helper.rb3
5 files changed, 71 insertions, 38 deletions
diff --git a/lib/helpers.rb b/lib/helpers.rb
index b14d357..b810142 100644
--- a/lib/helpers.rb
+++ b/lib/helpers.rb
@@ -1,11 +1,9 @@
-module Helpers
-
- def Helpers.include?(movies,movie)
+module Helpers
+ def include?(thing)
match = false
- movies.each do |m|
- match = true if m == movie
+ each do |t|
+ match = true if t == thing
end
match
end
-
end \ No newline at end of file
diff --git a/lib/movie_library.rb b/lib/movie_library.rb
new file mode 100644
index 0000000..3d0aa4a
--- /dev/null
+++ b/lib/movie_library.rb
@@ -0,0 +1,58 @@
+require 'helpers'
+
+ class MovieLibrary
+ include Helpers
+
+ def initialize(movies = [])
+ @movies = movies
+ end
+
+ def add(movie)
+ @movies.push(movie) unless include?(movie)
+ end
+
+ def total_count
+ @movies.size
+ end
+
+ def each
+ # @movies.count.times do |n|
+ # yield @movies[n]
+ # end
+
+ # n = 0
+ # loop do
+ # current = @movies[n]
+ # puts current
+ # return unless current
+ # yield current
+ # n += 1
+ # end
+
+ # for x in @movies
+ # yield x
+ # end
+
+ # i = 0
+ # current = @movies[i]
+ # while current do
+ # yield current
+ # current = @movies[i]
+ # i+=1
+ # end
+
+ # i = 0
+ # until i == @movies.count do
+ # yield @movies[i]
+ # i +=1
+ # end
+ #
+ i =0
+ yield @movies[i]; i+=1 until @movies.count==i
+ #
+
+ # puts "blah" while true
+
+
+ end
+ end \ No newline at end of file
diff --git a/lib/movielibrary.rb b/lib/movielibrary.rb
deleted file mode 100644
index 0090dfc..0000000
--- a/lib/movielibrary.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-require 'helpers'
-
-module MovieLibrary
-
- class MovieLibrary
-
- def initialize(movies = [])
- @movies = movies
- end
-
- def add(movie)
- @movies.push(movie) unless Helpers.include?(@movies,movie)
- end
-
- def total_count
- @movies.size
- end
-
- def include?(movie)
- match = false
- @movies.each do |m|
- match = true if m == movie
- end
- match
- end
-
- end
-end \ No newline at end of file
diff --git a/spec/lesson_three/movie_library_spec.rb b/spec/lesson_three/movie_library_spec.rb
index a22a7ed..59df3de 100644
--- a/spec/lesson_three/movie_library_spec.rb
+++ b/spec/lesson_three/movie_library_spec.rb
@@ -1,13 +1,15 @@
require "spec_helper"
-require "movielibrary"
-require "movie"
describe MovieLibrary do
- include MovieLibrary
- include Movie
+ # include MovieLibrary
+ # include Movie
context "when adding a movie to the library" do
+ it "should tell me what the load path is" do
+ puts $:
+ end
+
it "should increase the total number of movies in the library" do
library = MovieLibrary::MovieLibrary.new
shawshank_redemption = Movie::Movie.new("The Shawshank Redemption")
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index a579642..9ff33ae 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1 +1,4 @@
require "rspec"
+require "movie_library"
+require "movie"
+