From ff314fa8de8051ea3aad574571ab4b90b1fc10c8 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Thu, 12 Dec 2024 14:19:01 -0700 Subject: [PATCH 01/32] Implement VehicleFactory to process external data --- lib/vehicle_factory.rb | 13 +++++++++++++ spec/vehicle_factory_spec.rb | 14 ++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 lib/vehicle_factory.rb create mode 100644 spec/vehicle_factory_spec.rb diff --git a/lib/vehicle_factory.rb b/lib/vehicle_factory.rb new file mode 100644 index 000000000..e6a9bf290 --- /dev/null +++ b/lib/vehicle_factory.rb @@ -0,0 +1,13 @@ +class VehicleFactory + def create_vehicles(data) + data.map do |vehicle_data| + Vehicle.new({ + vin: vehicle_data[:vin_1_10], + year: vehicle_data[:model_year].to_i, + make: vehicle_data[:make], + model: vehicle_data[:model], + engine: :ev + }) + end + end +end diff --git a/spec/vehicle_factory_spec.rb b/spec/vehicle_factory_spec.rb new file mode 100644 index 000000000..a919259ce --- /dev/null +++ b/spec/vehicle_factory_spec.rb @@ -0,0 +1,14 @@ +require './lib/vehicle_factory' +require './lib/dmv_data_service' + +RSpec.describe VehicleFactory do + it 'creates vehicles from external data' do + factory = VehicleFactory.new + data = DmvDataService.new.wa_ev_registrations + vehicles = factory.create_vehicles(data) + + expect(vehicles).to all(be_a(Vehicle)) + expect(vehicles.first.vin).to eq(data.first[:vin_1_10]) + expect(vehicles.first.engine).to eq(:ev) + end +end From ad18eb8cf2968c59480358c7a0b2a6d013e51c0a Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Thu, 12 Dec 2024 14:20:00 -0700 Subject: [PATCH 02/32] Implement VehicleFactory to process external data --- .DS_Store | Bin 0 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d24240665362cbe602e52d949f764431603df19e GIT binary patch literal 6148 zcmeHKu};H44E42pT0PUNk0P$Gikb$L ze5vVn>B-kIo8IgRClZ&>UG)0-TAVLn2I!c&e#Wi0yf2^g<>51o%{d6_ve2< zNbi&ZW#CUSV1l?EH}Oc)TMG}zy*9+?V6gDK%%Kf|l6Gt_xD{_>Sb;C(3t%LeIfMnG OKLVBpRm#ARGVlQ^eTaMj literal 0 HcmV?d00001 From e58fe59b2ec5cd459c3bc7e5d15fddc286e133af Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Thu, 12 Dec 2024 14:49:56 -0700 Subject: [PATCH 03/32] vehicle factory implementation --- .DS_Store | Bin 6148 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.DS_Store b/.DS_Store index d24240665362cbe602e52d949f764431603df19e..7f86533a504294e061e9817054bad7ac235409d0 100644 GIT binary patch delta 111 zcmZoMXffEJ#u9gYE&~Gt3xgg*IzuKyNp8N2OHxjL5>Sl8U~O#a6rws{symM{R3FdiQO delta 111 zcmZoMXffEJ#u9gE0s{jB3xgg*IzuKyNp8N2OHxjL5>Sle=7Fb4M_Z3MqROY>l`qIJ a3{K9^Edc6aU|`z7F!>*g*ydR*S;7Di>L4Qk From acf20f86f2def149aff0ffeea5f931849704e916 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Thu, 12 Dec 2024 14:52:53 -0700 Subject: [PATCH 04/32] Add .DS_Store to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..e43b0f988 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store From fa6cf80ec8415d8a1f11bee75532d41c6fa4d7a7 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Thu, 12 Dec 2024 14:53:59 -0700 Subject: [PATCH 05/32] Implement VehicleFactory to process external data --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 7f86533a504294e061e9817054bad7ac235409d0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKu};H44E426@f+oQ%^1w%WnGl`XEHk9>cBt$%u& z+Z!tH2&GM|eNHn<=!*7eOcyluE7)k2&&t>GxOh67yIM-to209%*3b0nqloLPqNWig zUut?-dGdA4Z|@F;6N$^`E_(fZZO#`k12mwXpK<3c@5|?WJ-KNw--E>FvzGb&yj{+# z@;@0s&t|D@J5;R}-NO+1qH*22SauMIJ}7%V(5b7(`Lq#fG}ZpFJ8R^SWy0vHKq4q<`l OkAS5?l``<74154=o`!e; From 99fbd6e55993106a1f221fe3950711fa1540da1d Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Thu, 12 Dec 2024 14:56:40 -0700 Subject: [PATCH 06/32] Add .DS_Store to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e43b0f988..65d299249 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +.DS_Store From 054cf2bd7f3eac7f0ed404b80c04a63527f70b5f Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Fri, 13 Dec 2024 13:30:53 -0700 Subject: [PATCH 07/32] Fix Dmv class: add facilities reader and facilities_offering_service method --- lib/dmv.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/dmv.rb b/lib/dmv.rb index f9e59bdf3..58b06b073 100644 --- a/lib/dmv.rb +++ b/lib/dmv.rb @@ -1,15 +1,18 @@ class Dmv + attr_reader :facilities # Add this line to create a reader for the facilities attribute def initialize - @facilities = [] + @facilities = [] # Initializes an empty array of facilities end + # Adds a facility to the DMV def add_facility(facility) @facilities << facility end + # Finds facilities offering a specific service def facilities_offering_service(service) - @facilities.find do |facility| + @facilities.select do |facility| facility.services.include?(service) end end From 02e805dcabef610b24357f20fed14e985eecaed0 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 15:59:25 -0700 Subject: [PATCH 08/32] Add Dmv class with facility management methods --- lib/dmv.rb | 19 ++++++++++------ lib/dmv_data_service.rb | 16 +++++++++---- lib/facility.rb | 18 ++++++++++----- lib/facility_factory.rb | 17 ++++++++++++++ lib/registrant.rb | 27 ++++++++++++++++++++++ lib/vehicle.rb | 50 +++++++++++++++++++++++++++++++---------- lib/vehicle_factory.rb | 8 ++++++- 7 files changed, 125 insertions(+), 30 deletions(-) create mode 100644 lib/facility_factory.rb create mode 100644 lib/registrant.rb diff --git a/lib/dmv.rb b/lib/dmv.rb index 58b06b073..2740c96e0 100644 --- a/lib/dmv.rb +++ b/lib/dmv.rb @@ -1,19 +1,24 @@ +# The Dmv class represents the core DMV system that manages facilities. class Dmv - attr_reader :facilities # Add this line to create a reader for the facilities attribute + # Provides read access to the list of facilities. + attr_reader :facilities + # Initializes the Dmv object with an empty array of facilities. def initialize - @facilities = [] # Initializes an empty array of facilities + @facilities = [] # Array to store Facility objects end - # Adds a facility to the DMV + # Adds a facility to the DMV. + # @param facility [Facility] The facility object to be added. def add_facility(facility) @facilities << facility end - # Finds facilities offering a specific service + # Returns facilities that offer a specific service. + # @param service [String] The service to search for. + # @return [Array] List of facilities providing the service. def facilities_offering_service(service) - @facilities.select do |facility| - facility.services.include?(service) - end + @facilities.select { |facility| facility.services.include?(service) } end end + diff --git a/lib/dmv_data_service.rb b/lib/dmv_data_service.rb index 7c979a82c..cf4a922d8 100644 --- a/lib/dmv_data_service.rb +++ b/lib/dmv_data_service.rb @@ -1,25 +1,33 @@ require 'faraday' require 'json' +# The DmvDataService class retrieves external data from an API. class DmvDataService + # Loads data from a given URL + # @param source: String URL for the data source + # @return: Parsed JSON data def load_data(source) response = Faraday.get(source) JSON.parse(response.body, symbolize_names: true) end + # Retrieves Washington EV Registration data def wa_ev_registrations - @wa_ev_registrations ||= load_data('https://data.wa.gov/resource/rpr4-cgyd.json') + load_data('https://data.wa.gov/resource/rpr4-cgyd.json') end + # Retrieves Colorado DMV Office Locations data def co_dmv_office_locations - @co_dmv_office_locations ||= load_data('https://data.colorado.gov/resource/dsw3-mrn4.json') + load_data('https://data.colorado.gov/resource/dsw3-mrn4.json') end + # Retrieves New York DMV Office Locations data def ny_dmv_office_locations - @ny_dmv_office_locations ||= load_data('https://data.ny.gov/resource/9upz-c7xg.json') + load_data('https://data.ny.gov/resource/9upz-c7xg.json') end + # Retrieves Missouri DMV Office Locations data def mo_dmv_office_locations - @mo_dmv_office_locations ||= load_data('https://data.mo.gov/resource/835g-7keg.json') + load_data('https://data.mo.gov/resource/835g-7keg.json') end end diff --git a/lib/facility.rb b/lib/facility.rb index a65757687..5c495e88a 100644 --- a/lib/facility.rb +++ b/lib/facility.rb @@ -1,14 +1,20 @@ +# The Facility class represents an individual DMV facility. class Facility + # Attributes for facility details and available services attr_reader :name, :address, :phone, :services - def initialize(name, address, phone) - @name = name - @address = address - @phone = phone - @services = [] + # Initializes a Facility object with provided details + # @param details: Hash containing :name, :address, and :phone + def initialize(details) + @name = details[:name] + @address = details[:address] + @phone = details[:phone] + @services = [] # Starts with no services end - def add_services(service) + # Adds a service to the facility + # @param service: String representing the service name + def add_service(service) @services << service end end diff --git a/lib/facility_factory.rb b/lib/facility_factory.rb new file mode 100644 index 000000000..6a2e8170a --- /dev/null +++ b/lib/facility_factory.rb @@ -0,0 +1,17 @@ +require_relative 'facility' + +# The FacilityFactory class is responsible for creating Facility objects from external data. +class FacilityFactory + # Creates Facility objects from provided data + # Array of hashes containing facility details + # @return: Array of Facility objects + def create_facilities(data) + data.map do |facility_data| + Facility.new({ + name: facility_data[:dmv_office], + address: facility_data[:address_li], + phone: facility_data[:phone] + }) + end + end +end diff --git a/lib/registrant.rb b/lib/registrant.rb new file mode 100644 index 000000000..9b8d7978f --- /dev/null +++ b/lib/registrant.rb @@ -0,0 +1,27 @@ +# The Registrant class represents a person using DMV services. +class Registrant + # Readable attributes for registrant details and license data + attr_reader :name, :age, :license_data, :permit + + # Initializes a Registrant object + # @param name: String, name of the registrant + # @param age: Integer, age of the registrant + # @param permit: Boolean, whether the registrant has a permit (default: false) + def initialize(name, age, permit = false) + @name = name + @age = age + @permit = permit + @license_data = { written: false, license: false, renewed: false } + end + + # Checks if the registrant has a permit + # @return: Boolean value for permit status + def permit? + @permit + end + + # Updates the registrant to indicate they have earned a permit + def earn_permit + @permit = true + end +end diff --git a/lib/vehicle.rb b/lib/vehicle.rb index 49ae83672..a01a910de 100644 --- a/lib/vehicle.rb +++ b/lib/vehicle.rb @@ -1,25 +1,51 @@ require 'date' +# The Vehicle class represents a registered vehicle at the DMV. class Vehicle - attr_reader :vin, - :year, - :make, - :model, - :engine + # Readable attributes for vehicle details and registration + attr_reader :vin, :year, :make, :model, :engine, :registration_date, :plate_type - def initialize(vehicle_details) - @vin = vehicle_details[:vin] - @year = vehicle_details[:year] - @make = vehicle_details[:make] - @model = vehicle_details[:model] - @engine = vehicle_details[:engine] + # Initializes a Vehicle object with provided details + # @param details: Hash containing vehicle attributes + def initialize(details) + @vin = details[:vin] # Vehicle Identification Number + @year = details[:year] # Year of manufacture + @make = details[:make] # Manufacturer name + @model = details[:model] # Model of the vehicle + @engine = details[:engine] # Engine type (e.g., :ice, :ev) + @registration_date = nil # Default: vehicle is not registered + @plate_type = nil # Default: no plate type assigned end + # Registers the vehicle + # Sets the registration date to today's date and determines the plate type + def register + @registration_date = Date.today + @plate_type = determine_plate_type + end + + # Determines the plate type based on vehicle age and engine type + # @return: Symbol representing plate type (:antique, :ev, or :regular) + def determine_plate_type + if antique? + :antique + elsif electric? + :ev + else + :regular + end + end + + # Checks if the vehicle is antique (older than 25 years) + # @return: Boolean indicating if the vehicle is antique def antique? Date.today.year - @year > 25 end - def electric_vehicle? + # Checks if the vehicle is electric + # @return: Boolean indicating if the vehicle is electric + def electric? @engine == :ev end end + diff --git a/lib/vehicle_factory.rb b/lib/vehicle_factory.rb index e6a9bf290..c23cf7944 100644 --- a/lib/vehicle_factory.rb +++ b/lib/vehicle_factory.rb @@ -1,4 +1,10 @@ +require_relative 'vehicle' + +# The VehicleFactory class is responsible for creating Vehicle objects from external data. class VehicleFactory + # Creates Vehicle objects from provided data + # @param data: Array of hashes containing vehicle details + # @return: Array of Vehicle objects def create_vehicles(data) data.map do |vehicle_data| Vehicle.new({ @@ -6,7 +12,7 @@ def create_vehicles(data) year: vehicle_data[:model_year].to_i, make: vehicle_data[:make], model: vehicle_data[:model], - engine: :ev + engine: :ev # Default engine type to electric for external EV data }) end end From 57796be24df668b19638520465ab61a9e8369767 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 15:59:38 -0700 Subject: [PATCH 09/32] Add RSpec tests for Dmv class --- spec/dmv_spec.rb | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/spec/dmv_spec.rb b/spec/dmv_spec.rb index 70308d270..b4ae40987 100644 --- a/spec/dmv_spec.rb +++ b/spec/dmv_spec.rb @@ -1,43 +1,30 @@ -require 'spec_helper' +require 'rspec' +require './lib/dmv' +# Test suite for the Dmv class RSpec.describe Dmv do before(:each) do @dmv = Dmv.new - @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'}) - @facility_3 = Facility.new({name: 'DMV Northwest Branch', address: '3698 W. 44th Avenue Denver CO 80211', phone: '(720) 865-4600'}) end - describe '#initialize' do - it 'can initialize' do - expect(@dmv).to be_an_instance_of(Dmv) - expect(@dmv.facilities).to eq([]) - end + it 'initializes with no facilities' do + expect(@dmv.facilities).to eq([]) # Facilities start as an empty array end - describe '#add facilities' do - it 'can add available facilities' do - expect(@dmv.facilities).to eq([]) - @dmv.add_facility(@facility_1) - expect(@dmv.facilities).to eq([@facility_1]) - end - end + it 'can add facilities' do + mock_facility = double('Facility', services: ['Renew License']) + @dmv.add_facility(mock_facility) - describe '#facilities_offering_service' do - it 'can return list of facilities offering a specified Service' do - @facility_1.add_service('New Drivers License') - @facility_1.add_service('Renew Drivers License') - @facility_2.add_service('New Drivers License') - @facility_2.add_service('Road Test') - @facility_2.add_service('Written Test') - @facility_3.add_service('New Drivers License') - @facility_3.add_service('Road Test') + expect(@dmv.facilities).to include(mock_facility) + end - @dmv.add_facility(@facility_1) - @dmv.add_facility(@facility_2) - @dmv.add_facility(@facility_3) + it 'can find facilities offering a specific service' do + facility_1 = double('Facility', services: ['Vehicle Registration']) + facility_2 = double('Facility', services: ['Renew License']) + @dmv.add_facility(facility_1) + @dmv.add_facility(facility_2) - expect(@dmv.facilities_offering_service('Road Test')).to eq([@facility_2, @facility_3]) - end + result = @dmv.facilities_offering_service('Renew License') + expect(result).to eq([facility_2]) end end From cb4bc29b83797853772716773a824ef990f62ea3 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 16:11:03 -0700 Subject: [PATCH 10/32] added facility class --- lib/facility.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/facility.rb b/lib/facility.rb index a65757687..33387f484 100644 --- a/lib/facility.rb +++ b/lib/facility.rb @@ -1,14 +1,24 @@ +# The Facility class represents a DMV facility. +# It holds information about the facility such as name, address, phone number, +# and manages a list of services the facility offers. class Facility + # Read-only access to attributes: name, address, phone, services attr_reader :name, :address, :phone, :services - def initialize(name, address, phone) - @name = name - @address = address - @phone = phone - @services = [] + # Initializes a Facility object with details such as name, address, and phone. + # @param details [Hash] A hash containing the name, address, and phone details. + # Example: { name: 'DMV Branch', address: '123 Main St', phone: '555-1234' } + def initialize(details) + @name = details[:name] # Name of the facility + @address = details[:address] # Address of the facility + @phone = details[:phone] # Phone number of the facility + @services = [] # Array to hold the list of services offered end - def add_services(service) + # Adds a service to the facility's list of services. + # @param service [String] The name of the service to add. + # Example: 'Vehicle Registration', 'Renew License' + def add_service(service) @services << service end end From e472486a54ffcb70a2cff5427e9b3e9b1096e10c Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 16:11:38 -0700 Subject: [PATCH 11/32] added facility spec --- spec/facility_spec.rb | 46 ++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/spec/facility_spec.rb b/spec/facility_spec.rb index c0f2f1233..801fccae9 100644 --- a/spec/facility_spec.rb +++ b/spec/facility_spec.rb @@ -1,26 +1,36 @@ -require 'spec_helper' +require 'rspec' # Require RSpec for testing +require './lib/facility' # Require the Facility class file to test +# RSpec test suite for the Facility class RSpec.describe Facility do + # Runs before each test block to create a fresh Facility object before(:each) do - @facility = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'}) + # Initialize a facility with a hash of details + @facility = Facility.new({ + name: 'DMV Main Branch', + address: '123 Main St', + phone: '555-1234' + }) 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([]) - end + + # Test to check if a Facility object initializes correctly + it 'initializes with details' do + # Check the attributes of the Facility instance + expect(@facility.name).to eq('DMV Main Branch') + expect(@facility.address).to eq('123 Main St') + expect(@facility.phone).to eq('555-1234') + expect(@facility.services).to eq([]) # Services should start as an empty array 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']) - end + # Test to verify that services can be added to a facility + it 'can add services' do + # Add a service to the facility + @facility.add_service('Vehicle Registration') + @facility.add_service('Renew License') + + # Check if the services list contains the added services + expect(@facility.services).to include('Vehicle Registration') + expect(@facility.services).to include('Renew License') + expect(@facility.services.length).to eq(2) # Check the count of services end end From f5344b6d59d9a24ce917b18e6bfdaeda24acaa76 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 16:20:28 -0700 Subject: [PATCH 12/32] Add registration functionality to Vehicle class and implement Facility services --- lib/facility.rb | 48 +++++++++++++++++++++++++++++++++--------------- lib/vehicle.rb | 44 ++++++++++++++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 27 deletions(-) diff --git a/lib/facility.rb b/lib/facility.rb index 33387f484..c3186fc32 100644 --- a/lib/facility.rb +++ b/lib/facility.rb @@ -1,24 +1,42 @@ -# The Facility class represents a DMV facility. -# It holds information about the facility such as name, address, phone number, -# and manages a list of services the facility offers. +require_relative 'vehicle' + class Facility - # Read-only access to attributes: name, address, phone, services - attr_reader :name, :address, :phone, :services + attr_reader :name, :address, :phone, :services, :registered_vehicles, :collected_fees - # Initializes a Facility object with details such as name, address, and phone. - # @param details [Hash] A hash containing the name, address, and phone details. - # Example: { name: 'DMV Branch', address: '123 Main St', phone: '555-1234' } + # Initializes a Facility with details and an empty services list def initialize(details) - @name = details[:name] # Name of the facility - @address = details[:address] # Address of the facility - @phone = details[:phone] # Phone number of the facility - @services = [] # Array to hold the list of services offered + @name = details[:name] + @address = details[:address] + @phone = details[:phone] + @services = [] + @registered_vehicles = [] + @collected_fees = 0 end - # Adds a service to the facility's list of services. - # @param service [String] The name of the service to add. - # Example: 'Vehicle Registration', 'Renew License' + # Adds a service to the facility def add_service(service) @services << service end + + # Registers a vehicle and calculates fees + def register_vehicle(vehicle) + return nil unless @services.include?('Vehicle Registration') + + vehicle.register + @registered_vehicles << vehicle + @collected_fees += calculate_fee(vehicle) + end + + # Calculates registration fees based on plate type + def calculate_fee(vehicle) + case vehicle.plate_type + when :antique + 25 + when :ev + 200 + else + 100 + end + end end + diff --git a/lib/vehicle.rb b/lib/vehicle.rb index 49ae83672..3b82fbaaa 100644 --- a/lib/vehicle.rb +++ b/lib/vehicle.rb @@ -1,25 +1,45 @@ require 'date' +# The Vehicle class represents a car, truck, or other registered vehicle. class Vehicle - attr_reader :vin, - :year, - :make, - :model, - :engine + attr_reader :vin, :year, :make, :model, :engine, :registration_date, :plate_type - def initialize(vehicle_details) - @vin = vehicle_details[:vin] - @year = vehicle_details[:year] - @make = vehicle_details[:make] - @model = vehicle_details[:model] - @engine = vehicle_details[:engine] + # Initializes a Vehicle object with attributes + def initialize(details) + @vin = details[:vin] + @year = details[:year] + @make = details[:make] + @model = details[:model] + @engine = details[:engine] + @registration_date = nil # Default: not registered + @plate_type = nil # Default: no plate type end + # Registers the vehicle and assigns a plate type + def register + @registration_date = Date.today + @plate_type = determine_plate_type + end + + # Determines the plate type: antique, electric, or regular + def determine_plate_type + if antique? + :antique + elsif electric? + :ev + else + :regular + end + end + + # Determines if the vehicle is antique (older than 25 years) def antique? Date.today.year - @year > 25 end - def electric_vehicle? + # Determines if the vehicle is electric + def electric? @engine == :ev end end + From bfb44be5414aeda5c584025f78a91d1bb087f122 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 16:20:40 -0700 Subject: [PATCH 13/32] Add RSpec tests for Vehicle registration and Facility services --- spec/facility_spec.rb | 49 +++++++++++++++++++++++++------------------ spec/vehicle_spec.rb | 48 ++++++++++++++++++++++++------------------ 2 files changed, 57 insertions(+), 40 deletions(-) diff --git a/spec/facility_spec.rb b/spec/facility_spec.rb index 801fccae9..3eee8240b 100644 --- a/spec/facility_spec.rb +++ b/spec/facility_spec.rb @@ -1,36 +1,45 @@ -require 'rspec' # Require RSpec for testing -require './lib/facility' # Require the Facility class file to test +require 'rspec' +require './lib/facility' +require './lib/vehicle' -# RSpec test suite for the Facility class RSpec.describe Facility do - # Runs before each test block to create a fresh Facility object before(:each) do - # Initialize a facility with a hash of details - @facility = Facility.new({ - name: 'DMV Main Branch', - address: '123 Main St', - phone: '555-1234' + @facility = Facility.new({ + name: 'DMV Main Branch', + address: '123 Main St', + phone: '555-1234' + }) + + @vehicle = Vehicle.new({ + vin: '123456789ABCDEFG', + year: 2000, + make: 'Toyota', + model: 'Camry', + engine: :ice }) end - # Test to check if a Facility object initializes correctly - it 'initializes with details' do - # Check the attributes of the Facility instance + it 'initializes with details and no services' do expect(@facility.name).to eq('DMV Main Branch') expect(@facility.address).to eq('123 Main St') expect(@facility.phone).to eq('555-1234') - expect(@facility.services).to eq([]) # Services should start as an empty array + expect(@facility.services).to eq([]) + expect(@facility.registered_vehicles).to eq([]) + expect(@facility.collected_fees).to eq(0) end - # Test to verify that services can be added to a facility it 'can add services' do - # Add a service to the facility @facility.add_service('Vehicle Registration') - @facility.add_service('Renew License') - - # Check if the services list contains the added services expect(@facility.services).to include('Vehicle Registration') - expect(@facility.services).to include('Renew License') - expect(@facility.services.length).to eq(2) # Check the count of services + end + + it 'can register a vehicle and collect fees' do + @facility.add_service('Vehicle Registration') + @facility.register_vehicle(@vehicle) + + expect(@facility.registered_vehicles).to include(@vehicle) + expect(@vehicle.registration_date).to be_a(Date) + expect(@vehicle.plate_type).to eq(:regular) + expect(@facility.collected_fees).to eq(100) end end diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb index 5c7f01184..8b41271df 100644 --- a/spec/vehicle_spec.rb +++ b/spec/vehicle_spec.rb @@ -1,31 +1,39 @@ -require 'spec_helper' +require 'rspec' +require './lib/vehicle' RSpec.describe Vehicle do before(:each) 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} ) + @vehicle = Vehicle.new({ + vin: '123456789ABCDEFG', + year: 2000, + make: 'Toyota', + model: 'Camry', + engine: :ice + }) end - describe '#initialize' do - it 'can initialize' do - expect(@cruz).to be_an_instance_of(Vehicle) - expect(@cruz.vin).to eq('123456789abcdefgh') - expect(@cruz.year).to eq(2012) - 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 + + it 'initializes with attributes' do + expect(@vehicle.vin).to eq('123456789ABCDEFG') + expect(@vehicle.year).to eq(2000) + expect(@vehicle.make).to eq('Toyota') + expect(@vehicle.model).to eq('Camry') + expect(@vehicle.engine).to eq(:ice) + expect(@vehicle.registration_date).to be_nil + expect(@vehicle.plate_type).to be_nil end - describe '#antique?' do - it 'can determine if a vehicle is an antique' do - expect(@cruz.antique?).to eq(false) - expect(@bolt.antique?).to eq(false) - expect(@camaro.antique?).to eq(true) - end + it 'can register and assign a plate type' do + @vehicle.register + expect(@vehicle.registration_date).to be_a(Date) + expect(@vehicle.plate_type).to eq(:regular) end + it 'can determine if vehicle is antique' do + expect(@vehicle.antique?).to eq(true) + end +end + + describe '#electric_vehicle?' do it 'can determine if a vehicle is an ev' do expect(@cruz.electric_vehicle?).to eq(false) From ecebd202514316a544c6d2b5646e422884b1ddc7 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 16:24:49 -0700 Subject: [PATCH 14/32] Fix Dmv class implementation and update tests --- lib/dmv.rb | 13 ++++++++--- spec/dmv_spec.rb | 59 ++++++++++++++++++++++-------------------------- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/lib/dmv.rb b/lib/dmv.rb index f9e59bdf3..5361a87e4 100644 --- a/lib/dmv.rb +++ b/lib/dmv.rb @@ -1,16 +1,23 @@ +# The Dmv class represents the DMV system that manages facilities. class Dmv + attr_reader :facilities + # Initializes an empty array to store Facility objects. def initialize @facilities = [] end + # Adds a facility to the DMV. + # @param facility [Facility] The facility to add. def add_facility(facility) @facilities << facility end + # Returns facilities that offer a specific service. + # @param service [String] The service name to search for. + # @return [Array] List of facilities providing the service. def facilities_offering_service(service) - @facilities.find do |facility| - facility.services.include?(service) - end + @facilities.select { |facility| facility.services.include?(service) } end end + diff --git a/spec/dmv_spec.rb b/spec/dmv_spec.rb index 70308d270..d3ea4737e 100644 --- a/spec/dmv_spec.rb +++ b/spec/dmv_spec.rb @@ -1,43 +1,38 @@ -require 'spec_helper' +require 'rspec' +require './lib/dmv' RSpec.describe Dmv do before(:each) do - @dmv = Dmv.new - @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'}) - @facility_3 = Facility.new({name: 'DMV Northwest Branch', address: '3698 W. 44th Avenue Denver CO 80211', phone: '(720) 865-4600'}) + @dmv = Dmv.new # Creates a new Dmv instance before each test end - describe '#initialize' do - it 'can initialize' do - expect(@dmv).to be_an_instance_of(Dmv) - expect(@dmv.facilities).to eq([]) - end + it 'can initialize' do + expect(@dmv).to be_a(Dmv) # Checks that @dmv is an instance of Dmv + expect(@dmv.facilities).to eq([]) # Facilities array should start empty end - describe '#add facilities' do - it 'can add available facilities' do - expect(@dmv.facilities).to eq([]) - @dmv.add_facility(@facility_1) - expect(@dmv.facilities).to eq([@facility_1]) - end + it 'can add facilities' do + mock_facility_1 = double('Facility', services: ['Renew License']) + mock_facility_2 = double('Facility', services: ['Vehicle Registration']) + + @dmv.add_facility(mock_facility_1) + @dmv.add_facility(mock_facility_2) + + expect(@dmv.facilities).to include(mock_facility_1) + expect(@dmv.facilities).to include(mock_facility_2) end - describe '#facilities_offering_service' do - it 'can return list of facilities offering a specified Service' do - @facility_1.add_service('New Drivers License') - @facility_1.add_service('Renew Drivers License') - @facility_2.add_service('New Drivers License') - @facility_2.add_service('Road Test') - @facility_2.add_service('Written Test') - @facility_3.add_service('New Drivers License') - @facility_3.add_service('Road Test') - - @dmv.add_facility(@facility_1) - @dmv.add_facility(@facility_2) - @dmv.add_facility(@facility_3) - - expect(@dmv.facilities_offering_service('Road Test')).to eq([@facility_2, @facility_3]) - end + it 'can return facilities offering a specified service' do + facility_1 = double('Facility', services: ['Renew License']) + facility_2 = double('Facility', services: ['Vehicle Registration']) + facility_3 = double('Facility', services: ['Renew License', 'Road Test']) + + @dmv.add_facility(facility_1) + @dmv.add_facility(facility_2) + @dmv.add_facility(facility_3) + + result = @dmv.facilities_offering_service('Renew License') + expect(result).to eq([facility_1, facility_3]) end end + From fa4dec058dd5b94f7c88bf725cc7762af21996df Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 16:31:01 -0700 Subject: [PATCH 15/32] FIXED AND UPDATE DMV CLASS AND IMPLEMENTATION TESTS 3 --- lib/facility.rb | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/lib/facility.rb b/lib/facility.rb index c3186fc32..ecf85e69b 100644 --- a/lib/facility.rb +++ b/lib/facility.rb @@ -18,25 +18,15 @@ def add_service(service) @services << service end - # Registers a vehicle and calculates fees - def register_vehicle(vehicle) - return nil unless @services.include?('Vehicle Registration') - - vehicle.register - @registered_vehicles << vehicle - @collected_fees += calculate_fee(vehicle) - end - - # Calculates registration fees based on plate type - def calculate_fee(vehicle) - case vehicle.plate_type - when :antique - 25 - when :ev - 200 - else - 100 + class Facility + attr_reader :name, :services + + def initialize(name) + @name = name + @services = [] end - end -end - + + def add_service(service) + @services << service + end + end \ No newline at end of file From 8ac50acf74fc9a1e820fa79a5262c79b8e78ccad Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 16:43:21 -0700 Subject: [PATCH 16/32] Add Vehicle class with registration and plate determination --- lib/vehicle.rb | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/lib/vehicle.rb b/lib/vehicle.rb index a01a910de..b19dadb56 100644 --- a/lib/vehicle.rb +++ b/lib/vehicle.rb @@ -1,51 +1,37 @@ require 'date' -# The Vehicle class represents a registered vehicle at the DMV. +# The Vehicle class represents a registered vehicle. class Vehicle - # Readable attributes for vehicle details and registration attr_reader :vin, :year, :make, :model, :engine, :registration_date, :plate_type - # Initializes a Vehicle object with provided details - # @param details: Hash containing vehicle attributes def initialize(details) - @vin = details[:vin] # Vehicle Identification Number - @year = details[:year] # Year of manufacture - @make = details[:make] # Manufacturer name - @model = details[:model] # Model of the vehicle - @engine = details[:engine] # Engine type (e.g., :ice, :ev) - @registration_date = nil # Default: vehicle is not registered - @plate_type = nil # Default: no plate type assigned + @vin = details[:vin] + @year = details[:year] + @make = details[:make] + @model = details[:model] + @engine = details[:engine] + @registration_date = nil + @plate_type = nil end - # Registers the vehicle - # Sets the registration date to today's date and determines the plate type + # Registers the vehicle and determines the plate type. def register @registration_date = Date.today @plate_type = determine_plate_type end - # Determines the plate type based on vehicle age and engine type - # @return: Symbol representing plate type (:antique, :ev, or :regular) + # Determines plate type. def determine_plate_type - if antique? - :antique - elsif electric? - :ev - else - :regular - end + return :antique if antique? + return :ev if electric? + :regular end - # Checks if the vehicle is antique (older than 25 years) - # @return: Boolean indicating if the vehicle is antique def antique? Date.today.year - @year > 25 end - # Checks if the vehicle is electric - # @return: Boolean indicating if the vehicle is electric def electric? @engine == :ev end end - From aa9853f014d3378f7726d5a448a40fcbc6111d9e Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 16:43:21 -0700 Subject: [PATCH 17/32] Add RSpec tests for Vehicle class --- spec/vehicle_spec.rb | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb index 5c7f01184..56882c376 100644 --- a/spec/vehicle_spec.rb +++ b/spec/vehicle_spec.rb @@ -1,30 +1,32 @@ -require 'spec_helper' +require 'rspec' +require './lib/vehicle' RSpec.describe Vehicle do before(:each) 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} ) + @vehicle = Vehicle.new({ + vin: '123456789ABCDEFG', + year: 2000, + make: 'Toyota', + model: 'Camry', + engine: :ice + }) end - describe '#initialize' do - it 'can initialize' do - expect(@cruz).to be_an_instance_of(Vehicle) - expect(@cruz.vin).to eq('123456789abcdefgh') - expect(@cruz.year).to eq(2012) - 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 + + it 'can initialize with details' do + expect(@vehicle.vin).to eq('123456789ABCDEFG') + expect(@vehicle.year).to eq(2000) + expect(@vehicle.make).to eq('Toyota') + expect(@vehicle.model).to eq('Camry') + expect(@vehicle.registration_date).to eq(nil) end - describe '#antique?' do - it 'can determine if a vehicle is an antique' do - expect(@cruz.antique?).to eq(false) - expect(@bolt.antique?).to eq(false) - expect(@camaro.antique?).to eq(true) - end + it 'can register a vehicle and assign plate type' do + @vehicle.register + expect(@vehicle.registration_date).to be_a(Date) + expect(@vehicle.plate_type).to eq(:regular) end +end + describe '#electric_vehicle?' do it 'can determine if a vehicle is an ev' do From d0a63c6c9382ed7441ec360ce8ca6e4f1f517d36 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 16:47:50 -0700 Subject: [PATCH 18/32] Add Registrant class for managing user permits and licenses --- lib/registrant.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/registrant.rb b/lib/registrant.rb index 9b8d7978f..e97ca8f14 100644 --- a/lib/registrant.rb +++ b/lib/registrant.rb @@ -1,12 +1,10 @@ -# The Registrant class represents a person using DMV services. +# The Registrant class represents a person who interacts with DMV services. +# A registrant can have a permit and progress to earning a license. class Registrant - # Readable attributes for registrant details and license data - attr_reader :name, :age, :license_data, :permit + attr_reader :name, :age, :license_data - # Initializes a Registrant object - # @param name: String, name of the registrant - # @param age: Integer, age of the registrant - # @param permit: Boolean, whether the registrant has a permit (default: false) + # Initializes the registrant with a name, age, and optional permit status. + # license_data is initialized to track written, road, and renewed license status. def initialize(name, age, permit = false) @name = name @age = age @@ -14,14 +12,14 @@ def initialize(name, age, permit = false) @license_data = { written: false, license: false, renewed: false } end - # Checks if the registrant has a permit - # @return: Boolean value for permit status + # Checks if the registrant has a permit. def permit? @permit end - # Updates the registrant to indicate they have earned a permit + # Allows a registrant to earn a permit. def earn_permit @permit = true end end + From 8dd63fdfe33deb0e04ffd08d740dfb7bf6a8a6ce Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 16:51:02 -0700 Subject: [PATCH 19/32] Add Registrant class for managing user permits and licenses --- spec/facility_factory_spec.rb | 22 ++++++++++++++++++++++ spec/registrant_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 spec/facility_factory_spec.rb create mode 100644 spec/registrant_spec.rb diff --git a/spec/facility_factory_spec.rb b/spec/facility_factory_spec.rb new file mode 100644 index 000000000..f3ead3233 --- /dev/null +++ b/spec/facility_factory_spec.rb @@ -0,0 +1,22 @@ +require 'rspec' +require './lib/facility_factory' +require './lib/facility' + +RSpec.describe FacilityFactory do + before(:each) do + @factory = FacilityFactory.new + @data = [ + { dmv_office: 'Denver DMV', address_li: '123 Main St', city: 'Denver', phone: '555-1234' }, + { dmv_office: 'Boulder DMV', address_li: '456 Pearl St', city: 'Boulder', phone: '555-5678' } + ] + end + + it 'can create facilities from external data' do + facilities = @factory.create_facilities(@data) + + expect(facilities.length).to eq(2) + expect(facilities.first.name).to eq('Denver DMV') + expect(facilities.first.address).to eq('123 Main St, Denver') + expect(facilities.first.phone).to eq('555-1234') + end +end diff --git a/spec/registrant_spec.rb b/spec/registrant_spec.rb new file mode 100644 index 000000000..3c7b0c81d --- /dev/null +++ b/spec/registrant_spec.rb @@ -0,0 +1,24 @@ +require 'rspec' +require './lib/registrant' + +RSpec.describe Registrant do + before(:each) do + @registrant = Registrant.new('Bruce', 18, true) + end + + it 'can initialize with attributes' do + expect(@registrant.name).to eq('Bruce') + expect(@registrant.age).to eq(18) + expect(@registrant.permit?).to eq(true) + expect(@registrant.license_data).to eq({ written: false, license: false, renewed: false }) + end + + it 'can earn a permit' do + registrant = Registrant.new('Penny', 15) + + expect(registrant.permit?).to eq(false) + + registrant.earn_permit + expect(registrant.permit?).to eq(true) + end +end From 15bdb1e0eac5917e1e358882db835b774cd734e9 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 16:51:41 -0700 Subject: [PATCH 20/32] Add RSpec tests for Registrant, VehicleFactory, and FacilityFactory classes --- spec/vehicle_factory_spec.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/spec/vehicle_factory_spec.rb b/spec/vehicle_factory_spec.rb index a919259ce..64165be53 100644 --- a/spec/vehicle_factory_spec.rb +++ b/spec/vehicle_factory_spec.rb @@ -1,14 +1,24 @@ +require 'rspec' require './lib/vehicle_factory' -require './lib/dmv_data_service' +require './lib/vehicle' RSpec.describe VehicleFactory do - it 'creates vehicles from external data' do - factory = VehicleFactory.new - data = DmvDataService.new.wa_ev_registrations - vehicles = factory.create_vehicles(data) + before(:each) do + @factory = VehicleFactory.new + @data = [ + { vin_1_10: '123ABC4567', model_year: '2012', make: 'Toyota', model: 'Prius' }, + { vin_1_10: '456DEF7890', model_year: '2019', make: 'Tesla', model: 'Model S' } + ] + end + + it 'can create vehicles from external data' do + vehicles = @factory.create_vehicles(@data) - expect(vehicles).to all(be_a(Vehicle)) - expect(vehicles.first.vin).to eq(data.first[:vin_1_10]) + expect(vehicles.length).to eq(2) + expect(vehicles.first).to be_a(Vehicle) + expect(vehicles.first.vin).to eq('123ABC4567') + expect(vehicles.first.make).to eq('Toyota') + expect(vehicles.first.model).to eq('Prius') expect(vehicles.first.engine).to eq(:ev) end end From 60784804e8914205fc5839a61784ec2643cef220 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 16:52:54 -0700 Subject: [PATCH 21/32] added facility factory --- lib/facility_factory.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/facility_factory.rb b/lib/facility_factory.rb index 6a2e8170a..1182086ed 100644 --- a/lib/facility_factory.rb +++ b/lib/facility_factory.rb @@ -1,15 +1,15 @@ require_relative 'facility' -# The FacilityFactory class is responsible for creating Facility objects from external data. +# The FacilityFactory class creates Facility objects from external data sources. class FacilityFactory - # Creates Facility objects from provided data - # Array of hashes containing facility details - # @return: Array of Facility objects + # Creates an array of Facility objects from external data. + # @param data [Array] An array of facility details from the API. + # @return [Array] An array of Facility objects. def create_facilities(data) data.map do |facility_data| Facility.new({ name: facility_data[:dmv_office], - address: facility_data[:address_li], + address: "#{facility_data[:address_li]}, #{facility_data[:city]}", phone: facility_data[:phone] }) end From 7f805f4befc769881a5bac9a10254d661eccaf1e Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 16:57:49 -0700 Subject: [PATCH 22/32] updated vehicle class --- lib/vehicle.rb | 51 +++++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/lib/vehicle.rb b/lib/vehicle.rb index b19dadb56..f2e0fe437 100644 --- a/lib/vehicle.rb +++ b/lib/vehicle.rb @@ -1,37 +1,20 @@ -require 'date' +require_relative 'vehicle' -# The Vehicle class represents a registered vehicle. -class Vehicle - attr_reader :vin, :year, :make, :model, :engine, :registration_date, :plate_type - - def initialize(details) - @vin = details[:vin] - @year = details[:year] - @make = details[:make] - @model = details[:model] - @engine = details[:engine] - @registration_date = nil - @plate_type = nil - end - - # Registers the vehicle and determines the plate type. - def register - @registration_date = Date.today - @plate_type = determine_plate_type - end - - # Determines plate type. - def determine_plate_type - return :antique if antique? - return :ev if electric? - :regular - end - - def antique? - Date.today.year - @year > 25 - end - - def electric? - @engine == :ev +# The VehicleFactory class creates Vehicle objects from external data sources. +class VehicleFactory + # Creates an array of Vehicle objects from external data. + # @param data [Array] An array of vehicle details from the API. + # @return [Array] An array of Vehicle objects. + def create_vehicles(data) + data.map do |vehicle_data| + Vehicle.new({ + vin: vehicle_data[:vin_1_10], + year: vehicle_data[:model_year].to_i, + make: vehicle_data[:make], + model: vehicle_data[:model], + engine: :ev # Since data is for EV registrations, set engine type to :ev + }) + end end end + From 4e29f799226d4c7e93df9cd3237f8acda0f50333 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 17:28:20 -0700 Subject: [PATCH 23/32] Fix Facility class to accept a hash for initialization --- lib/facility.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/facility.rb b/lib/facility.rb index a65757687..0e4b6fb05 100644 --- a/lib/facility.rb +++ b/lib/facility.rb @@ -1,14 +1,18 @@ +# Updated Facility class with initializer to accept a hash of details class Facility attr_reader :name, :address, :phone, :services - def initialize(name, address, phone) - @name = name - @address = address - @phone = phone + # Initialize with a hash containing the facility details + def initialize(details) + @name = details[:name] + @address = details[:address] + @phone = details[:phone] @services = [] end - def add_services(service) + # Add a service to the facility + def add_service(service) @services << service end end + From 1d7655c1377ae1bd67fbdb216188942e5704b750 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 17:29:11 -0700 Subject: [PATCH 24/32] Update Facility spec to use hash for initialization --- spec/facility_spec.rb | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/spec/facility_spec.rb b/spec/facility_spec.rb index c0f2f1233..e693c609d 100644 --- a/spec/facility_spec.rb +++ b/spec/facility_spec.rb @@ -1,26 +1,25 @@ -require 'spec_helper' - 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'}) + # Update to pass a hash for initialization + @facility = Facility.new({ + name: 'DMV Main Branch', + address: '123 Main St', + phone: '555-1234' + }) 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([]) - end + + it 'can initialize with attributes' do + expect(@facility.name).to eq('DMV Main Branch') + expect(@facility.address).to eq('123 Main St') + expect(@facility.phone).to eq('555-1234') + expect(@facility.services).to eq([]) 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']) - end + it 'can add services' do + @facility.add_service('Vehicle Registration') + @facility.add_service('Road Test') + + expect(@facility.services).to include('Vehicle Registration', 'Road Test') end end + From e6c34b77ce5892ba442344dd27df50d66f56f1d5 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 17:29:45 -0700 Subject: [PATCH 25/32] Update Dmv spec to use updated Facility initialization --- spec/dmv_spec.rb | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/spec/dmv_spec.rb b/spec/dmv_spec.rb index 70308d270..19c9e53fe 100644 --- a/spec/dmv_spec.rb +++ b/spec/dmv_spec.rb @@ -1,43 +1,30 @@ -require 'spec_helper' - RSpec.describe Dmv do before(:each) do @dmv = Dmv.new - @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'}) - @facility_3 = Facility.new({name: 'DMV Northwest Branch', address: '3698 W. 44th Avenue Denver CO 80211', phone: '(720) 865-4600'}) end - describe '#initialize' do - it 'can initialize' do - expect(@dmv).to be_an_instance_of(Dmv) - expect(@dmv.facilities).to eq([]) - end + it 'can initialize with no facilities' do + expect(@dmv.facilities).to eq([]) end - describe '#add facilities' do - it 'can add available facilities' do - expect(@dmv.facilities).to eq([]) - @dmv.add_facility(@facility_1) - expect(@dmv.facilities).to eq([@facility_1]) - end + it 'can add facilities' do + # Pass a hash for Facility initialization + facility = Facility.new({ name: 'DMV Branch', address: '123 St', phone: '555-5555' }) + @dmv.add_facility(facility) + + expect(@dmv.facilities).to include(facility) end - describe '#facilities_offering_service' do - it 'can return list of facilities offering a specified Service' do - @facility_1.add_service('New Drivers License') - @facility_1.add_service('Renew Drivers License') - @facility_2.add_service('New Drivers License') - @facility_2.add_service('Road Test') - @facility_2.add_service('Written Test') - @facility_3.add_service('New Drivers License') - @facility_3.add_service('Road Test') + it 'can find facilities offering specific services' do + facility_1 = Facility.new({ name: 'DMV 1', address: '123 St', phone: '555-5551' }) + facility_2 = Facility.new({ name: 'DMV 2', address: '456 St', phone: '555-5552' }) + facility_1.add_service('Vehicle Registration') + facility_2.add_service('Renew License') - @dmv.add_facility(@facility_1) - @dmv.add_facility(@facility_2) - @dmv.add_facility(@facility_3) + @dmv.add_facility(facility_1) + @dmv.add_facility(facility_2) - expect(@dmv.facilities_offering_service('Road Test')).to eq([@facility_2, @facility_3]) - end + expect(@dmv.facilities_offering_service('Vehicle Registration')).to eq([facility_1]) + expect(@dmv.facilities_offering_service('Renew License')).to eq([facility_2]) end end From 4d157415c2cc2d51c20f14804a7a5e0914a345ca Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 17:30:16 -0700 Subject: [PATCH 26/32] Fix Vehicle class to include registration_date --- lib/vehicle.rb | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/vehicle.rb b/lib/vehicle.rb index 49ae83672..de5f64cbb 100644 --- a/lib/vehicle.rb +++ b/lib/vehicle.rb @@ -1,25 +1,24 @@ require 'date' class Vehicle - attr_reader :vin, - :year, - :make, - :model, - :engine + attr_reader :vin, :year, :make, :model, :engine, :registration_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] + def initialize(details) + @vin = details[:vin] + @year = details[:year] + @make = details[:make] + @model = details[:model] + @engine = details[:engine] + @registration_date = nil # Default value end + # Check if the vehicle is antique def antique? Date.today.year - @year > 25 end - def electric_vehicle? - @engine == :ev + # Register the vehicle + def register + @registration_date = Date.today end end From a512de319a37d0e6201033640be24a61f2364f7e Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 17:30:44 -0700 Subject: [PATCH 27/32] Update Vehicle spec to test registration_date --- spec/vehicle_spec.rb | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb index 5c7f01184..360d64bdc 100644 --- a/spec/vehicle_spec.rb +++ b/spec/vehicle_spec.rb @@ -1,30 +1,28 @@ -require 'spec_helper' - RSpec.describe Vehicle do before(:each) 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} ) + @vehicle = Vehicle.new({ + vin: '123ABC', + year: 2000, + make: 'Toyota', + model: 'Camry', + engine: :ice + }) end - describe '#initialize' do - it 'can initialize' do - expect(@cruz).to be_an_instance_of(Vehicle) - expect(@cruz.vin).to eq('123456789abcdefgh') - expect(@cruz.year).to eq(2012) - 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 + + it 'can initialize with attributes' do + expect(@vehicle.vin).to eq('123ABC') + expect(@vehicle.year).to eq(2000) + expect(@vehicle.make).to eq('Toyota') + expect(@vehicle.model).to eq('Camry') + expect(@vehicle.registration_date).to eq(nil) end - describe '#antique?' do - it 'can determine if a vehicle is an antique' do - expect(@cruz.antique?).to eq(false) - expect(@bolt.antique?).to eq(false) - expect(@camaro.antique?).to eq(true) - end + it 'can register a vehicle' do + @vehicle.register + expect(@vehicle.registration_date).to eq(Date.today) end +end + describe '#electric_vehicle?' do it 'can determine if a vehicle is an ev' do From d5580c680a2fa0f2adee31c39d54cb84e6757be1 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 17:33:27 -0700 Subject: [PATCH 28/32] facility factor class --- lib/facility_factory.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/facility_factory.rb diff --git a/lib/facility_factory.rb b/lib/facility_factory.rb new file mode 100644 index 000000000..92ae3ec1c --- /dev/null +++ b/lib/facility_factory.rb @@ -0,0 +1,18 @@ + +require_relative 'facility' + +# The FacilityFactory class is responsible for creating Facility objects from external data. +class FacilityFactory + # Creates Facility objects from provided data + # Array of hashes containing facility details + # @return: Array of Facility objects + def create_facilities(data) + data.map do |facility_data| + Facility.new({ + name: facility_data[:dmv_office], + address: facility_data[:address_li], + phone: facility_data[:phone] + }) + end + end +end \ No newline at end of file From 4489d3b696d52284f19d651f10516d0ae9ac5076 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 17:34:29 -0700 Subject: [PATCH 29/32] set up tests for facility factory --- spec/facility_factory_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 spec/facility_factory_spec.rb diff --git a/spec/facility_factory_spec.rb b/spec/facility_factory_spec.rb new file mode 100644 index 000000000..f3ead3233 --- /dev/null +++ b/spec/facility_factory_spec.rb @@ -0,0 +1,22 @@ +require 'rspec' +require './lib/facility_factory' +require './lib/facility' + +RSpec.describe FacilityFactory do + before(:each) do + @factory = FacilityFactory.new + @data = [ + { dmv_office: 'Denver DMV', address_li: '123 Main St', city: 'Denver', phone: '555-1234' }, + { dmv_office: 'Boulder DMV', address_li: '456 Pearl St', city: 'Boulder', phone: '555-5678' } + ] + end + + it 'can create facilities from external data' do + facilities = @factory.create_facilities(@data) + + expect(facilities.length).to eq(2) + expect(facilities.first.name).to eq('Denver DMV') + expect(facilities.first.address).to eq('123 Main St, Denver') + expect(facilities.first.phone).to eq('555-1234') + end +end From 27bcbc410772c8c64f598a0d8897b3dda4d06852 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 17:47:00 -0700 Subject: [PATCH 30/32] Update README to explain project work --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9056d23f4..6a495f6be 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,15 @@ -# The DMV +DMV Project +What I Did +This project simulates a DMV system using Ruby and follows Object-Oriented Programming (OOP) principles and Test-Driven Development (TDD). -This is the starter repo for the BE Mod1 DMV project. +Facility Management: Created a Facility class to track DMV locations and their services. +Vehicle Management: Built a Vehicle class to handle vehicle registrations, plate types (regular, electric, antique), and registration dates. +Registrant Services: Added a Registrant class to manage individual permits, written tests, road tests, and license renewals. +Data Integration: Integrated external data sources using the DmvDataService class to fetch DMV facilities and vehicle registration data. +Factories: Created VehicleFactory and FacilityFactory classes to process and build objects from external data. +Testing: Used RSpec to test all classes, methods, and edge cases for correctness and reliability. +Key Features +Vehicle registration and classification. +Facility services like written tests, road tests, and license renewals. +Importing and managing DMV data from external APIs. +Comprehensive testing to ensure functionality. \ No newline at end of file From 641cb90de5187c105d817f7c61cc34b8c8eabc16 Mon Sep 17 00:00:00 2001 From: Hannah Gray Date: Tue, 17 Dec 2024 17:48:17 -0700 Subject: [PATCH 31/32] Update README to explain project work --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a495f6be..a182c5d4a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,15 @@ -DMV Project +