diff --git a/Gemfile.lock b/Gemfile.lock index d273a79f9..9546e6b0b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,6 +29,7 @@ GEM PLATFORMS arm64-darwin-20 arm64-darwin-21 + arm64-darwin-23 DEPENDENCIES faraday diff --git a/lib/dmv.rb b/lib/dmv.rb index f9e59bdf3..c54dc8312 100644 --- a/lib/dmv.rb +++ b/lib/dmv.rb @@ -1,4 +1,5 @@ class Dmv + attr_reader :facilities def initialize @facilities = [] @@ -9,8 +10,9 @@ def add_facility(facility) end def facilities_offering_service(service) - @facilities.find do |facility| + @facilities.find_all do |facility| facility.services.include?(service) end end + end diff --git a/lib/dmv_facilities.rb b/lib/dmv_facilities.rb new file mode 100644 index 000000000..4ac63629b --- /dev/null +++ b/lib/dmv_facilities.rb @@ -0,0 +1,19 @@ +class DMVFacilities + attr_reader :facilities + + def initialize + @facilities = [] + end + + def create_facilities(facility_data) + @facilities = [] + facility_data.each do |facility| + new_facility = Facility.new({ + :name => "#{facility[:dmv_office]}#{facility[:office_name]}#{facility[:name]}", + :address => "#{facility[:address_li]}#{facility[:street_address_line_1]}#{facility[:address1]} #{facility[:city]} #{facility[:state]} #{facility[:zip_code]}#{facility[:zipcode]}", + :phone => "#{facility[:phone]}#{facility[:public_phone_number]}" + }) + @facilities << new_facility + end + end +end \ No newline at end of file diff --git a/lib/facility.rb b/lib/facility.rb index a65757687..e2e5a33d8 100644 --- a/lib/facility.rb +++ b/lib/facility.rb @@ -1,14 +1,73 @@ class Facility - attr_reader :name, :address, :phone, :services + attr_reader :name, + :address, + :phone, + :services, + :registered_vehicles, + :collected_fees - def initialize(name, address, phone) - @name = name - @address = address - @phone = phone + def initialize(facility_details) + @name = facility_details[:name] + @address = facility_details[:address] + @phone = facility_details[:phone] @services = [] + @registered_vehicles = [] + @collected_fees = 0 end - def add_services(service) + def add_service(service) @services << service end + + def register_vehicle(vehicle) + + if @services.include?('Vehicle Registration') + @registered_vehicles << vehicle + end + + end + + def collect_fee(vehicle) + + if vehicle.year < 1999 + @collected_fees += 25 + elsif vehicle.engine == :ev + @collected_fees += 200 + else + @collected_fees += 100 + end + + end + + def administer_written_test(registrant) + + if @services.include?('Written Test') && registrant.permit? == true && registrant.age >= 16 + registrant.change_license_data(:written) + true + else + return false + end + + end + + def administer_road_test(registrant) + + if @services.include?('Road Test') && registrant.age >= 16 && registrant.license_data[:written] == true + registrant.change_license_data(:license) + true + else + return false + end + + end + + def renew_drviers_license(registrant) + if @services.include?('Renew License') && registrant.license_data[:written] == true && registrant.license_data[:license] == true + registrant.change_license_data(:renewed) + true + else + return false + end + end + end diff --git a/lib/registrant.rb b/lib/registrant.rb new file mode 100644 index 000000000..3588bff37 --- /dev/null +++ b/lib/registrant.rb @@ -0,0 +1,29 @@ +require 'pry' + +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 = permit + end + + def earn_permit + @permit = true + end + + def change_license_data(key) + @license_data[key] = true + end +end \ No newline at end of file diff --git a/lib/vehicle.rb b/lib/vehicle.rb index 49ae83672..da76ce874 100644 --- a/lib/vehicle.rb +++ b/lib/vehicle.rb @@ -5,7 +5,10 @@ class Vehicle :year, :make, :model, - :engine + :engine, + :registration_date, + :plate_type + def initialize(vehicle_details) @vin = vehicle_details[:vin] @@ -13,6 +16,7 @@ def initialize(vehicle_details) @make = vehicle_details[:make] @model = vehicle_details[:model] @engine = vehicle_details[:engine] + @plate_type = plate_type end def antique? @@ -22,4 +26,18 @@ def antique? def electric_vehicle? @engine == :ev end + + def register + @registration_date = Date.today + + if antique? + @plate_type = :antique + elsif electric_vehicle? + @plate_type = :ev + else + @plate_type = :regular + end + + end + end diff --git a/lib/vehicle_factory.rb b/lib/vehicle_factory.rb new file mode 100644 index 000000000..1b1fb6904 --- /dev/null +++ b/lib/vehicle_factory.rb @@ -0,0 +1,22 @@ +class VehicleFactory + attr_reader :created_vehicles + + def initialize + @created_vehicles = [] + end + + def create_vehicles(vehicle_data) + @created_vehicles = [] + vehicle_data.each do |vehicle| + new_vehicle = Vehicle.new ({ + :vin => vehicle[:vin_1_10], + :year => vehicle[:model_year], + :make => vehicle[:make], + :model => vehicle[:model], + :engine => :ev + }) + @created_vehicles << new_vehicle + end + end + +end \ No newline at end of file diff --git a/spec/dmv_data_service_spec.rb b/spec/dmv_data_service_spec.rb index 7baf709a0..986136f6d 100644 --- a/spec/dmv_data_service_spec.rb +++ b/spec/dmv_data_service_spec.rb @@ -42,4 +42,4 @@ expect(@dds.mo_dmv_office_locations.size).to be_an(Integer) end end -end +end diff --git a/spec/dmv_facilities_spec.rb b/spec/dmv_facilities_spec.rb new file mode 100644 index 000000000..243d66be6 --- /dev/null +++ b/spec/dmv_facilities_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +RSpec.describe DMVFacilities do + + before(:each) do + @facility = DMVFacilities.new + end + + describe '#initialize' do + it 'checks DMVFacilities class exists' do + expect(@facility).to be_a(DMVFacilities) + end + end + + describe '#creates colorado facilities' do + it 'can create colorado facilities' do + co_dmv_office_locations = DmvDataService.new.co_dmv_office_locations + @facility.create_facilities(co_dmv_office_locations) + expect(@facility.facilities[0].name).to eq('DMV Tremont Branch') + expect(@facility.facilities[0].address).to eq('2855 Tremont Place Denver CO ') + expect(@facility.facilities[0].phone).to eq('(720) 865-4600') + end + end + + describe '#creates new york facilities' do + it 'can create new york facilities' do + ny_dmv_office_locations = DmvDataService.new.ny_dmv_office_locations + @facility.create_facilities(ny_dmv_office_locations) + expect(@facility.facilities[1].name).to eq('HUDSON') + expect(@facility.facilities[1].address).to eq("560 WARREN STREET HUDSON NY 12534") + expect(@facility.facilities[1].phone).to eq('5188283350') + end + end + + describe '#creates missouri facilities' do + it 'can create missouri facilities' do + mo_dmv_office_locations = DmvDataService.new.mo_dmv_office_locations + @facility.create_facilities(mo_dmv_office_locations) + expect(@facility.facilities[0].name).to eq('Harrisonville') + expect(@facility.facilities[0].address).to eq("2009 Plaza Dr. Harrisonville MO 64701") + expect(@facility.facilities[0].phone).to eq('(816) 884-4133') + end + end + +end \ No newline at end of file diff --git a/spec/facility_spec.rb b/spec/facility_spec.rb index c0f2f1233..9cb44c7e2 100644 --- a/spec/facility_spec.rb +++ b/spec/facility_spec.rb @@ -2,25 +2,154 @@ 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} ) + + @registrant_1 = Registrant.new("Bruce", 18, true) + @registrant_2 = Registrant.new("Penny", 16) + @registrant_3 = Registrant.new('Tucker', 15 ) end + describe '#initialize' do + it 'can initialize' do - expect(@facility).to be_an_instance_of(Facility) - expect(@facility.name).to eq('DMV Tremont Branch') - expect(@facility.address).to eq('2855 Tremont Place Suite 118 Denver CO 80205') - expect(@facility.phone).to eq('(720) 865-4600') - expect(@facility.services).to eq([]) + expect(@facility_1).to be_an_instance_of(Facility) + expect(@facility_1.name).to eq('DMV Tremont Branch') + expect(@facility_1.address).to eq('2855 Tremont Place Suite 118 Denver CO 80205') + expect(@facility_1.phone).to eq('(720) 865-4600') + expect(@facility_1.services).to eq([]) + + expect(@facility_2).to be_an_instance_of(Facility) + expect(@facility_2.name).to eq('DMV Northeast Branch') + expect(@facility_2.address).to eq('4685 Peoria Street Suite 101 Denver CO 80239') + expect(@facility_2.phone).to eq('(720) 865-4600') + expect(@facility_2.services).to eq([]) end end describe '#add service' do + it 'can add available services' do - expect(@facility.services).to eq([]) - @facility.add_service('New Drivers License') - @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.services).to eq([]) + @facility_1.add_service('New Drivers License') + @facility_1.add_service('Renew Drivers License') + @facility_1.add_service('Vehicle Registration') + @facility_1.add_service('Road Test') + @facility_1.add_service('Written Test') + + expect(@facility_1.services).to eq(['New Drivers License', 'Renew Drivers License', 'Vehicle Registration', 'Road Test', 'Written Test']) + expect(@facility_2.services).to eq([]) + end + end + + describe '#add registration details' do + + it 'can register vehicles' do + @facility_1.add_service('Vehicle Registration') + @facility_1.register_vehicle(@cruz) + @facility_1.register_vehicle(@camero) + @facility_1.register_vehicle(@bolt) + @facility_2.register_vehicle(@bolt) + expect(@facility_1.registered_vehicles).to eq([@cruz, @camero, @bolt]) + expect(@facility_2.registered_vehicles).to eq([]) + end + + it 'has a registration date for each car' do + expect(@cruz.registration_date).to eq(nil) + end + + it 'has a list of registered vehicles' do + expect(@facility_1.registered_vehicles).to eq ([]) + expect(@facility_2.registered_vehicles).to eq ([]) + end + + it 'keeps track of collected fees' do + expect(@facility_1.collected_fees).to eq(0) + end + + it 'checks that fees are collected when a vehicle is registered' do + @facility_1.collect_fee(@cruz) + @facility_1.collect_fee(@camaro) + @facility_1.collect_fee(@bolt) + expect(@facility_1.collected_fees).to eq(325) + expect(@facility_2.collected_fees).to eq(0) + end + end + + describe '#testing details'do + it 'checks that facility has written test service' do + expect(@facility_1.administer_written_test(@registrant_1)).to eq(false) + end + + it 'can administer a written test'do + @facility_1.add_service('Written Test') + expect(@facility_1.administer_written_test(@registrant_1)).to eq(true) + expect(@registrant_1.license_data).to eq({:written =>true, :license =>false, :renewed =>false}) + end + + it 'checks for registrants permit status' do + @facility_1.add_service('Written Test') + expect(@facility_1.administer_written_test(@registrant_2)).to eq(false) + + @registrant_2.earn_permit + expect(@facility_1.administer_written_test(@registrant_2)).to eq(true) + expect(@registrant_2.license_data).to eq({:written =>true, :license =>false, :renewed =>false}) + end + + it 'checks that registrant is at least 16' do + @facility_1.add_service('Written Test') + @registrant_3.earn_permit + + expect(@facility_1.administer_written_test(@registrant_3)).to eq(false) + expect(@registrant_3.license_data).to eq({:written =>false, :license =>false, :renewed =>false}) + end + + it 'checks facility has road test service' do + expect(@facility_1.administer_road_test(@registrant_1)).to eq(false) + end + + it 'can administer road test' do + @facility_1.add_service('Written Test') + @facility_1.add_service('Road Test') + @facility_1.administer_written_test(@registrant_1) + @facility_1.administer_road_test(@registrant_1) + @registrant_2.earn_permit + @facility_1.administer_written_test(@registrant_2) + @facility_1.administer_road_test(@registrant_2) + expect(@facility_1.administer_road_test(@registrant_1)).to eq(true) + expect(@facility_1.administer_road_test(@registrant_2)).to eq(true) + expect(@registrant_1.license_data).to eq({:written =>true,:license =>true,:renewed =>false}) + expect(@registrant_2.license_data).to eq({:written =>true,:license =>true,:renewed =>false}) + end + end + + describe '#renew license'do + it 'checks facility for renew license service' do + expect(@facility_1.renew_drviers_license(@registrant_1)).to eq(false) + end + + it 'can renew license' do + @facility_1.add_service('Written Test') + @facility_1.add_service('Road Test') + @facility_1.add_service('Renew License') + @facility_1.administer_written_test(@registrant_1) + @facility_1.administer_road_test(@registrant_1) + @facility_1.renew_drviers_license(@registrant_1) + @registrant_2.earn_permit + @facility_1.administer_written_test(@registrant_2) + @facility_1.administer_road_test(@registrant_2) + @facility_1.renew_drviers_license(@registrant_3) + expect(@facility_1.renew_drviers_license(@registrant_1)).to eq(true) + expect(@facility_1.renew_drviers_license(@registrant_3)).to eq(false) + expect(@facility_1.renew_drviers_license(@registrant_2)).to eq(true) + expect(@registrant_1.license_data).to eq({:written =>true,:license =>true,:renewed =>true}) + expect(@registrant_2.license_data).to eq({:written =>true,:license =>true,:renewed =>true}) + expect(@registrant_3.license_data).to eq({:written =>false,:license =>false,:renewed =>false}) end end end diff --git a/spec/registrant_spec.rb b/spec/registrant_spec.rb new file mode 100644 index 000000000..cbbe5571e --- /dev/null +++ b/spec/registrant_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +RSpec.describe Registrant do + before(:each) do + @registrant_1 = Registrant.new("Bruce", 18, true) + @registrant_2 = Registrant.new("Penny", 15) + @registrant_3 = Registrant.new('Tucker', 15 ) + end + + describe '#initialize'do + it 'can initialize' do + expect(@registrant_1). to be_an_instance_of(Registrant) + expect(@registrant_2). to be_an_instance_of(Registrant) + expect(@registrant_3). to be_an_instance_of(Registrant) + end + end + + describe '#registrant data' do + it 'can store names'do + expect(@registrant_1.name). to eq("Bruce") + expect(@registrant_2.name). to eq("Penny") + expect(@registrant_3.name). to eq("Tucker") + end + + it 'can store ages' do + expect(@registrant_1.age).to eq(18) + expect(@registrant_2.age).to eq(15) + expect(@registrant_3.age).to eq(15) + end + + it 'can tell if they have a permit'do + expect(@registrant_1.permit?). to eq(true) + expect(@registrant_2.permit?). to eq(false) + expect(@registrant_3.permit?). to eq(false) + end + + it 'can pull license data'do + expect(@registrant_1.license_data).to eq({:written =>false, :license => false, :renewed => false}) + expect(@registrant_2.license_data).to eq({:written =>false, :license => false, :renewed => false}) + expect(@registrant_3.license_data).to eq({:written =>false, :license => false, :renewed => false}) + end + + it 'can let registrants earn permit'do + @registrant_2.earn_permit + expect(@registrant_2.permit?).to eq(true) + end + end + + +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 928255386..6ab5a0636 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,3 +3,6 @@ require './lib/facility' require './lib/vehicle' require './lib/dmv_data_service' +require './lib/registrant' +require './lib/dmv_facilities' +require './lib/vehicle_factory' diff --git a/spec/vehicle_factory_spec.rb b/spec/vehicle_factory_spec.rb new file mode 100644 index 000000000..c7e6d8486 --- /dev/null +++ b/spec/vehicle_factory_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +RSpec.describe VehicleFactory do + + before(:each) do + @factory = VehicleFactory.new + end + + describe '#initialize' do + it 'checks Vehicle Factory class exists' do + expect(@factory).to be_a(VehicleFactory) + end + end + + describe '#creates vehicles' do + it 'can create vehicles' do + wa_ev_registrations = DmvDataService.new.wa_ev_registrations + @factory.create_vehicles(wa_ev_registrations) + + expect(@factory.created_vehicles[0].vin).to eq('WBY8P8C51K') + expect(@factory.created_vehicles[0].year).to eq('2019') + expect(@factory.created_vehicles[0].make).to eq('BMW') + expect(@factory.created_vehicles[0].model).to eq('i3') + expect(@factory.created_vehicles[0].engine).to eq(:ev) + end + end + +end \ No newline at end of file diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb index 5c7f01184..aa66cd6a7 100644 --- a/spec/vehicle_spec.rb +++ b/spec/vehicle_spec.rb @@ -6,6 +6,7 @@ @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(@cruz).to be_an_instance_of(Vehicle) @@ -14,7 +15,6 @@ expect(@cruz.make).to eq('Chevrolet') expect(@cruz.model).to eq('Cruz') expect(@cruz.engine).to eq(:ice) - expect(@cruz.registration_date).to eq(nil) end end @@ -33,4 +33,24 @@ expect(@camaro.electric_vehicle?).to eq(false) end end + + describe '#registration details'do + it 'can detect registration date'do + @cruz.register + @camaro.register + @bolt.register + expect(@cruz.registration_date).to eq(Date.today) + expect(@camaro.registration_date).to eq(Date.today) + expect(@bolt.registration_date).to eq(Date.today) + end + + it '#can check vehicle plate type'do + @cruz.register + @camaro.register + @bolt.register + expect(@cruz.plate_type).to eq(:regular) + expect(@camaro.plate_type).to eq(:antique) + expect(@bolt.plate_type).to eq(:ev) + end + end end