diff --git a/Gemfile.lock b/Gemfile.lock index 0facad0..72dbdde 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,6 +18,7 @@ GEM i18n (0.6.0) multi_json (1.3.4) pg (0.13.2) + pg (0.13.2-x86-mingw32) rake (0.9.2.2) rspec (2.10.0) rspec-core (~> 2.10.0) @@ -31,6 +32,7 @@ GEM PLATFORMS ruby + x86-mingw32 DEPENDENCIES activerecord diff --git a/block_review.rb b/block_review.rb index fcdefc7..21f0c67 100644 --- a/block_review.rb +++ b/block_review.rb @@ -2,6 +2,20 @@ require 'bundler/setup' require_relative 'db/setup' -Dir.glob("./**/*.rb").each {|f| require f} +Dir.glob("./models/*.rb").each {|f| require f} +auto1 = Automobile.new(color: "white", make: "Ford", model: "Explorer", year: "2000") +auto2 = Automobile.new(color: "blue", make: "Honda", model: "Accord", year: "2009") +auto3 = Automobile.new(color: "blue", make: "Honda", model: "Accord", year: "2011") + +puts "An automobile has #{Automobile.number_of_wheels} tires." +puts "A motorcycle has #{Motorcycle.number_of_wheels} tires." +puts +puts "Auto 1: #{auto1.to_s}" +puts "Auto 2: #{auto2.to_s}" +puts "Auto 3: #{auto3.to_s}" +puts +puts "All vehicles: #{Vehicle.vehicles.inspect}" +puts "All blue Honda Accords: #{Vehicle.get_favorite_combo}" +puts puts "Serenity now!" diff --git a/config/database.yml.sample b/config/database.yml.sample deleted file mode 100644 index 2e5c2a9..0000000 --- a/config/database.yml.sample +++ /dev/null @@ -1,6 +0,0 @@ -host: 'localhost' -adapter: 'postgresql' -database: 'episode5' -username: XXXXXXX -encoding: 'utf8' -pool: 5 diff --git a/models/automobile.rb b/models/automobile.rb new file mode 100644 index 0000000..8176d85 --- /dev/null +++ b/models/automobile.rb @@ -0,0 +1,9 @@ +require_relative "Vehicle" + +class Automobile < Vehicle + + def self.number_of_wheels + @wheels = 4 + end + +end \ No newline at end of file diff --git a/models/motorcycle.rb b/models/motorcycle.rb new file mode 100644 index 0000000..7565ddb --- /dev/null +++ b/models/motorcycle.rb @@ -0,0 +1,9 @@ +require_relative "Vehicle" + +class Motorcycle < Vehicle + + def self.number_of_wheels + @wheels = 2 + end + +end \ No newline at end of file diff --git a/models/vehicle.rb b/models/vehicle.rb new file mode 100644 index 0000000..744b3d0 --- /dev/null +++ b/models/vehicle.rb @@ -0,0 +1,42 @@ +class Vehicle + + @@vehicles = [] + + def self.get_favorite_combo + veh = @@vehicles.select { |i| i.color == "blue" && + i.make == "Honda" && i.model == "Accord" } + end + + def self.reset + @@vehicles = [] + end + + def self.number_of_wheels + @wheels = nil + end + + def self.vehicles + @@vehicles + end + + attr_reader :color, :make, :model, :year + def initialize (hash={}) + @@vehicles << self + @color = hash.fetch(:color) + @make = hash.fetch(:make) + @model = hash.fetch(:model) + @year = hash.fetch(:year) + end + + def update (hash={}) + @color = hash.fetch(:color) + @make = hash.fetch(:make) + @model = hash.fetch(:model) + @year = hash.fetch(:year) + end + + def to_s + "#{year} #{color} #{make} #{model}" + end + +end \ No newline at end of file diff --git a/spec/automobile_spec.rb b/spec/automobile_spec.rb new file mode 100644 index 0000000..673c3e0 --- /dev/null +++ b/spec/automobile_spec.rb @@ -0,0 +1,10 @@ +require "rspec" +require_relative "../models/automobile" + +describe Automobile do + + it "should have four wheels" do + Automobile.number_of_wheels.should eq(4) + end + +end \ No newline at end of file diff --git a/spec/motorcycle_spec.rb b/spec/motorcycle_spec.rb new file mode 100644 index 0000000..cfea09d --- /dev/null +++ b/spec/motorcycle_spec.rb @@ -0,0 +1,10 @@ +require "rspec" +require_relative "../models/motorcycle" + +describe Motorcycle do + + it "should have two wheels" do + Motorcycle.number_of_wheels.should eq(2) + end + +end \ No newline at end of file diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb new file mode 100644 index 0000000..4ac2909 --- /dev/null +++ b/spec/vehicle_spec.rb @@ -0,0 +1,52 @@ +require "rspec" +require_relative "../models/vehicle" + +describe Vehicle do + + before(:each) do + Vehicle.reset + end + + it "should have four wheels" do + Vehicle.number_of_wheels.should eq(nil) + end + + it "class should keep track of the vehicles made" do + Vehicle.vehicles.should_not be(nil) + Vehicle.vehicles.count.should eq(0) + veh = Vehicle.new(color: "white", make: "Honda", model: "Accord", year: "2002") + Vehicle.vehicles.count.should eq(1) + end + + + it "should take input to describe the automobile" do + auto = Vehicle.new(color: "black", make: "Honda", model: "Accord", year: "2002") + auto.color.should eq("black") + auto.make.should eq("Honda") + auto.model.should eq("Accord") + auto.year.should eq("2002") + end + + it "should allow an update to the automobile" do + auto = Vehicle.new(color: "silver", make: "Toyota", model: "Camry", year: "2012") + auto.update(color: "red", make: "Honda", model: "Accord", year: "2002") + auto.color.should eq("red") + auto.make.should eq("Honda") + auto.model.should eq("Accord") + auto.year.should eq("2002") + end + + it "should filter the vehicles list to only show blue Honda Accords" do + auto1 = Vehicle.new(color: "blue", make: "Honda", model: "Accord", year: "2002") + auto2 = Vehicle.new(color: "blue", make: "Honda", model: "Accord", year: "2005") + auto3 = Vehicle.new(color: "silver", make: "Toyota", model: "Camry", year: "2012") + results = Vehicle.get_favorite_combo + results.count.should eq(2) + end + + it "should allow the class to be reset" do + auto = Vehicle.new(color: "silver", make: "Toyota", model: "Camry", year: "2012") + Vehicle.reset + Vehicle.vehicles.count.should eq(0) + end +end \ No newline at end of file