diff --git a/Gemfile.lock b/Gemfile.lock index d273a79f9..6def29197 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,6 +29,7 @@ GEM PLATFORMS arm64-darwin-20 arm64-darwin-21 + arm64-darwin-24 DEPENDENCIES faraday diff --git a/lib/dmv.rb b/lib/dmv.rb index f9e59bdf3..ec8d32863 100644 --- a/lib/dmv.rb +++ b/lib/dmv.rb @@ -1,5 +1,6 @@ class Dmv +attr_reader :facilities def initialize @facilities = [] end @@ -9,7 +10,7 @@ def add_facility(facility) end def facilities_offering_service(service) - @facilities.find do |facility| + @facilities.select do |facility| facility.services.include?(service) end end diff --git a/lib/facility.rb b/lib/facility.rb index a65757687..3a4658580 100644 --- a/lib/facility.rb +++ b/lib/facility.rb @@ -1,14 +1,40 @@ class Facility - attr_reader :name, :address, :phone, :services + attr_reader :name, :address, :phone, :services, :registered_vehicles, :plate_type, :registration_cost, :collected_fees - def initialize(name, address, phone) - @name = name - @address = address - @phone = phone + def initialize (facility_hash) + @name = facility_hash[:name] + @address = facility_hash[:address] + @phone = facility_hash[:phone] @services = [] + @registered_vehicles = [] + @collected_fees = 0 end - - def add_services(service) + + def add_service(service) @services << service end + + + + + def register_vehicle(vehicle) +binding.pry + if vehicle.antique? + vehicle.update_plate_type(:antique) + @collected_fees += 25 + elsif vehicle.electric_vehicle? + vehicle.update_plate_type(:ev) + @collected_fees += 200 + else + vehicle.update_plate_type(:regular) + @collected_fees += 100 + + end + binding.pry + @registration_date = Date.today + + @registered_vehicles << vehicle + end + end + diff --git a/lib/registrant.rb b/lib/registrant.rb new file mode 100644 index 000000000..3dedc50d6 --- /dev/null +++ b/lib/registrant.rb @@ -0,0 +1,22 @@ +class Registrant + attr_reader :name, :age, :permit, :license_data + + def initialize(name, age, permit = false) + @name = name + @age = age + @permit = permit + @license_data = {:written=>false, :license=>false, :renewed=>false} + end + + def permit? + @permit + end + + def earn_permit + @permit = true + end + +end + + + diff --git a/lib/vehicle.rb b/lib/vehicle.rb index 49ae83672..2b2bc878c 100644 --- a/lib/vehicle.rb +++ b/lib/vehicle.rb @@ -5,21 +5,36 @@ class Vehicle :year, :make, :model, - :engine + :engine, + :plate_type, + :antique, + :register_date + def initialize(vehicle_details) @vin = vehicle_details[:vin] @year = vehicle_details[:year] @make = vehicle_details[:make] @model = vehicle_details[:model] @engine = vehicle_details[:engine] + @registration_date = nil + @plate_type = nil + end + + def update_registration_date + @registration_date = Date.today end def antique? - Date.today.year - @year > 25 + Date.today.year - @year >= 25 end def electric_vehicle? @engine == :ev end + + def update_plate_type(type) + @plate_type = type + end + end diff --git a/spec/facility_services.rb b/spec/facility_services.rb new file mode 100644 index 000000000..b189dace0 --- /dev/null +++ b/spec/facility_services.rb @@ -0,0 +1,102 @@ +require 'spec_helper' +require 'RSpec' + +RSpec.describe Facility do + it 'exists' do + facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'}) + facility_2 = Facility.new({name: 'DMV Northeast Branch', address: '4685 Peoria Street Suite 101 Denver CO 80239', phone: '(720) 865-4600'}) + + expect(facility_1).to be_an_instance_of(Facility) + expect(facility_2).to be_an_instance_of(Facility) + end + + describe Vehicle do + it 'exists' do + cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice}) + bolt = Vehicle.new({vin: '987654321abcdefgh', year: 2019, make: 'Chevrolet', model: 'Bolt', engine: :ev}) + camaro = Vehicle.new({vin: '1a2b3c4d5e6f', year: 1969, make: 'Chevrolet', model: 'Camaro', engine: :ice}) + + expect(cruz).to be_an_instance_of(Vehicle) + expect(bolt).to be_an_instance_of(Vehicle) + expect(camaro).to be_an_instance_of(Vehicle) + end + end + + # it "adds new service" do + # facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'}) + # facility_1.add_service('Vehicle Registration') + + # expect(facility_1.services).to include('Vehicle Registration') + # end + + # it 'returns nil for cruz registration date' do + # cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice}) + + # expect(cruz.registration_date).to eq(nil) + #end + + # it 'returns [] for registered vehicles' do + # facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'}) + + # expect(facility_1.registered_vehicles).to eq([]) + + # end + + # it 'returns [] for collected fees' do + # facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'}) + + # expect(facility_1.collected_fees).to eq(0) + + # end + + # it 'registers a vehicle' do + # facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'}) + # cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice}) + + # expect(facility_1.register_vehicle(cruz)).to include(cruz) + #end + it 'returns cruz registration date' do + facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'}) + cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice}) + + facility_1.register_vehicle(cruz) + + + expect(cruz.registration_date).to eq(Date.today) + end + + it "return plate type for cruz" do + facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'}) + cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice}) + + facility_1.register_vehicle(cruz) + + expect(cruz.plate_type).to eq(:regular) + end + + it 'a vehicle has been registered' do + facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'}) + cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice}) + + facility_1.register_vehicle(cruz) + expect(facility_1.registered_vehicles).to include(cruz) + + end + + it "updates collected fees when vehicle is registered" do + facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'}) + cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice}) + + facility_1.register_vehicle(cruz) + expect(facility_1.collected_fees).to eq(100) + end + + + + + + +end + + + diff --git a/spec/facility_spec.rb b/spec/facility_spec.rb index c0f2f1233..cb8455819 100644 --- a/spec/facility_spec.rb +++ b/spec/facility_spec.rb @@ -3,7 +3,13 @@ RSpec.describe Facility do before(:each) do @facility = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'}) + @facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'}) + @facility_2 = Facility.new({name: 'DMV Northeast Branch', address: '4685 Peoria Street Suite 101 Denver CO 80239', phone: '(720) 865-4600'}) + @cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice} ) + @bolt = Vehicle.new({vin: '987654321abcdefgh', year: 2019, make: 'Chevrolet', model: 'Bolt', engine: :ev} ) + @camaro = Vehicle.new({vin: '1a2b3c4d5e6f', year: 1969, make: 'Chevrolet', model: 'Camaro', engine: :ice} ) end + describe '#initialize' do it 'can initialize' do expect(@facility).to be_an_instance_of(Facility) @@ -21,6 +27,30 @@ @facility.add_service('Renew Drivers License') @facility.add_service('Vehicle Registration') expect(@facility.services).to eq(['New Drivers License', 'Renew Drivers License', 'Vehicle Registration']) + expect(@facility_1.add_service('Vehicle Registration')).to eq(['Vehicle Registration']) end end + it "returns [] for registered vehicles" do + expect(@facility_1.registered_vehicles).to eq([]) + + end + + it 'returns 0 for collected fees' do + expect(@facility_1.collected_fees).to eq(0) + end + + it "can register a vehicle" do + expect(@facility_1.register_vehicle(@cruz)).to eq([@cruz]) + end + + it 'updates registration date' do + today = Date.today + expect(@cruz.registration_date).to eq(nil) + @facility_1.register_vehicle(@cruz) + expect(@cruz.registration_date).to eq(today) + end + + + + end diff --git a/spec/registrant_spec.rb b/spec/registrant_spec.rb new file mode 100644 index 000000000..847eb2eab --- /dev/null +++ b/spec/registrant_spec.rb @@ -0,0 +1,42 @@ +require './lib/registrant' +require 'spec_helper' + +RSpec.describe Registrant do + it "exists" do + registrant_1 = Registrant.new('Bruce', 18, true) + registrant_2 = Registrant.new('Penny', 15) + + expect(registrant_1).to be_an_instance_of(Registrant) + expect(registrant_2).to be_an_instance_of(Registrant) + end + + it 'returns attributes registrant 1' do + registrant_1 = Registrant.new('Bruce', 18, true) + + expect(registrant_1.name).to eq("Bruce") + expect(registrant_1.age).to eq(18) + expect(registrant_1.permit?).to eq(true) + expect(registrant_1.license_data).to eq({:written=>false, :license=>false, :renewed=>false}) + end + + it 'returns attributes registrant 2' do + registrant_2 = Registrant.new('Penny', 15) + + expect(registrant_2.name).to eq("Penny") + expect(registrant_2.age).to eq(15) + expect(registrant_2.license_data).to eq({:written=>false, :license=>false, :renewed=>false}) + end + + it "returns if permit is earned" do + registrant_1 = Registrant.new('Bruce', 18, true) + registrant_2 = Registrant.new('Penny', 15) + + expect(registrant_2.permit?).to eq(false) + registrant_1.earn_permit + expect(registrant_1.permit?).to eq(true) + + end + +end + + \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 928255386..58d13198f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,3 +3,4 @@ require './lib/facility' require './lib/vehicle' require './lib/dmv_data_service' +require './lib/registrant' diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb index 5c7f01184..f1514002d 100644 --- a/spec/vehicle_spec.rb +++ b/spec/vehicle_spec.rb @@ -33,4 +33,11 @@ expect(@camaro.electric_vehicle?).to eq(false) end end + it 'returns nil for cruz registration date' do + cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice}) + + expect(cruz.registration_date).to eq(nil) + end + + end