Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joseph Bloom #603

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a71e671
initial commit
Jsphbloom Dec 12, 2024
33eb057
3 failures left iteration 1
Jsphbloom Dec 12, 2024
4c50e16
adding registrant class
Jsphbloom Dec 12, 2024
ed95d41
new branch
Jsphbloom Dec 12, 2024
e71198b
creating registrant spec
Jsphbloom Dec 12, 2024
a186a9b
no error in spec
Jsphbloom Dec 12, 2024
8bb800e
iteration 1 done, rspec file complete
Jsphbloom Dec 12, 2024
5ed6bc4
Merge pull request #1 from Jsphbloom/iteration-1-branch-1
Jsphbloom Dec 12, 2024
d1cd4be
first branch 2 commit
Jsphbloom Dec 12, 2024
4f7b779
register vehicle method
Jsphbloom Dec 13, 2024
dc95fb8
adding plate type to vehicle class
Jsphbloom Dec 13, 2024
e351fe1
registered vehicles and collected fees methods, plus spec testing
Jsphbloom Dec 13, 2024
6b65c77
rspec tests for registered vehicles and collected fees
Jsphbloom Dec 13, 2024
85e71a9
more plate_type work, trying hashes to no avail
Jsphbloom Dec 15, 2024
87ad2fb
ditched hashes. modifying the plate type in the register vehicle method
Jsphbloom Dec 15, 2024
c836229
moved test to vehicle_spec. duh.
Jsphbloom Dec 15, 2024
a4f3a30
vehicle registration complete
Jsphbloom Dec 15, 2024
e1812b2
can administer written test if included in services
Jsphbloom Dec 15, 2024
af0412d
can administer a road test too, and set the license value to true
Jsphbloom Dec 15, 2024
c6ee681
can renew a drivers license too
Jsphbloom Dec 15, 2024
80ab761
adding conditions to methods
Jsphbloom Dec 15, 2024
33cc813
cleaning up, fixing tests, adding more conditionals to my if statemen…
Jsphbloom Dec 15, 2024
5fd1b5a
created vehicle factory file and accompanying spec file. testing some…
Jsphbloom Dec 15, 2024
3df417d
forgot to require the vehiclefactory file, it can initialize now
Jsphbloom Dec 15, 2024
39c7909
broken create_vehicles method. testing how to incorporate API data
Jsphbloom Dec 15, 2024
9efc280
progress on create vehicles method. Fix spec test next(oops)
Jsphbloom Dec 15, 2024
b2cd589
messing with create vehicles
Jsphbloom Dec 16, 2024
f630d9a
iteration 2 complete boom baby
Jsphbloom Dec 16, 2024
bcf42c3
iteration 3 start
Jsphbloom Dec 16, 2024
e7245d8
iteration 3 begins
Jsphbloom Dec 17, 2024
30493a4
Merge pull request #2 from Jsphbloom/iteration2branch2
Jsphbloom Dec 17, 2024
d070708
fixing it3
Jsphbloom Dec 17, 2024
21e93be
Merge branch 'main' into Iteration3branch3
Jsphbloom Dec 17, 2024
5130b52
REAL iteration 3 begins
Jsphbloom Dec 17, 2024
560c19e
Merge pull request #3 from Jsphbloom/iteration3branch3
Jsphbloom Dec 17, 2024
6d547af
iteration 3 looking good. new dmv_facilities class and accompanying s…
Jsphbloom Dec 17, 2024
43e7557
Merge pull request #4 from Jsphbloom/iteration3branch3
Jsphbloom Dec 17, 2024
39ae304
iteration 4 begins
Jsphbloom Dec 17, 2024
3790ac3
Merge pull request #5 from Jsphbloom/iteration4branch4
Jsphbloom Dec 17, 2024
b049375
Merge pull request #6 from Jsphbloom/iteration4branch4
Jsphbloom Dec 17, 2024
068c527
Merge pull request #7 from Jsphbloom/iteration3branch3
Jsphbloom Dec 17, 2024
73efab8
spec tests looking nice on dmv_facilities_spec
Jsphbloom Dec 17, 2024
9f23f63
Merge pull request #8 from Jsphbloom/iteration4branch4
Jsphbloom Dec 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ GEM
PLATFORMS
arm64-darwin-20
arm64-darwin-21
universal-darwin-24

DEPENDENCIES
faraday
Expand Down
11 changes: 8 additions & 3 deletions lib/dmv.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
class Dmv
require 'pry'

class Dmv
attr_reader :facilities
def initialize
@facilities = []
end

def add_facility(facility)
@facilities << facility
@facilities << facility
end

def facilities_offering_service(service)
@facilities.find do |facility|
@facilities.find_all do |facility|
facility.services.include?(service)
end
end


end
#branch 3/333
19 changes: 19 additions & 0 deletions lib/dmv_facilities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require './lib/facility'
require './lib/dmv_data_service'


class DmvFacilities

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might make more sense to call this class DMVFactory to match the Vehicle Factory naming convention

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree ^

attr_accessor :facilities
def initialize
@facilities = []
end

def create_facilities(facility_details)
facility_details.each do |facility|
new_facility = Facility.new(facility)
@facilities << new_facility
end
return @facilities
end
end

55 changes: 50 additions & 5 deletions lib/facility.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,59 @@
class Facility
attr_reader :name, :address, :phone, :services

def initialize(name, address, phone)
@name = name
@address = address
@phone = phone
def initialize(facility_details)
@name = facility_details[:name] || facility_details[:dmv_office] || facility_details[:office_name]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of this OR logic 😉

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you B)

@address = facility_details[:address] || facility_details[:address_li] || facility_details[:street_address_line_1] || facility_details[:address1]
@phone = facility_details[:phone] || facility_details[:public_phone_number]
@services = []
@registered_vehicles = []
@collected_fees = 0
end

def add_services(service)
def add_service(service)
@services << service
end

def registered_vehicles
@registered_vehicles
end

def collected_fees
@collected_fees
end

def register_vehicle(vehicle)
vehicle.registration_date = Date.today.strftime("%m/%d/%Y")
if vehicle.antique?
@collected_fees += 25
@registered_vehicles << vehicle
elsif vehicle.engine == :ev
@collected_fees += 200
@registered_vehicles << vehicle
else
@collected_fees += 100
@registered_vehicles << vehicle
end
end

def administer_written_test(registrant)
if @services.include?("Written Test") && registrant.permit? == true
registrant.license_data[:written] = true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely works, but it would be a little better if there was a method on the registrant class that managed this change. It could either be explicitly exposing license_data as an attr_writer or attr_accessor, or you could create a method to earn_written_license that would change the value from inside the registrant.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense! i thought it was a little weird that I was handling this from facility.

end
return registrant.license_data[:written]
end

def administer_road_test(registrant)
if @services.include?("Road Test") && registrant.license_data[:written] == true
registrant.license_data[:license] = true
end
return registrant.license_data[:license]
end

def renew_drivers_license(registrant)
if @services.include?("Renew License") && registrant.license_data[:license] == true
registrant.license_data[:renewed] = true
end
return registrant.license_data[:renewed]
end
end
30 changes: 30 additions & 0 deletions lib/registrant.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@


class Registrant

attr_reader :name,
:age,
: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

#branch 2!
26 changes: 21 additions & 5 deletions lib/vehicle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,37 @@ class Vehicle
:year,
:make,
:model,
:engine
:engine,
:plate_type

attr_accessor :registration_date


def initialize(vehicle_details)
@vin = vehicle_details[:vin]
@year = vehicle_details[:year]
@vin = vehicle_details[:vin_1_10]
@year = vehicle_details[:model_year]
@make = vehicle_details[:make]
@model = vehicle_details[:model]
@engine = vehicle_details[:engine]
@plate_type = nil
@registration_date = nil
end

def antique?
Date.today.year - @year > 25
Date.today.year - @year.to_i > 25
end

def electric_vehicle?
@engine == :ev
end

def plate_type
if antique?
@plate_type = :antique
elsif @engine == :ev
@plate_type = :ev
else
@plate_type = :regular
end
end
end
18 changes: 18 additions & 0 deletions lib/vehicle_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require './lib/vehicle'
require './lib/dmv_data_service'


class VehicleFactory
attr_accessor :cars
def initialize
@cars = []
end

def create_vehicles(vehicle_details)
vehicle_details.each do |vehicle|
new_vehicle = Vehicle.new(vehicle)
@cars << new_vehicle
end
return @cars
end
end
65 changes: 65 additions & 0 deletions spec/dmv_facilities_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require 'spec_helper'
require 'pry'

RSpec.describe DmvFacilities do
before do
@dmvfacilities = DmvFacilities.new
@co_dmv_office_locations = DmvDataService.new.co_dmv_office_locations
@ny_dmv_office_locations = DmvDataService.new.ny_dmv_office_locations
@mo_dmv_office_locations = DmvDataService.new.mo_dmv_office_locations
end

describe "#initialize" do
it 'can initialize' do
expect(@dmvfacilities).to be_an_instance_of(DmvFacilities)
end
end

describe "#create CO facilities" do
it 'can create CO facilities and hold facility details' do
@dmvfacilities.create_facilities(@co_dmv_office_locations)
expect(@dmvfacilities.facilities.length).to eq(5)
expect(@dmvfacilities.facilities[1].name).to eq("DMV Northeast Branch")
expect(@dmvfacilities.facilities[1].phone).to eq("(720) 865-4600")
expect(@dmvfacilities.facilities[1].address).to eq("4685 Peoria Street")
end
end

describe "#create NY facilities" do
it 'can create NY facilities and hold facility details' do
@dmvfacilities.create_facilities(@ny_dmv_office_locations)
expect(@dmvfacilities.facilities.length).to eq(173)
expect(@dmvfacilities.facilities[0].name).to eq("LAKE PLACID")
expect(@dmvfacilities.facilities[1].name).to eq("HUDSON")
expect(@dmvfacilities.facilities[2].name).to eq("RIVERHEAD KIOSK")
end
end

describe "#create MO facilities" do
it 'can create MO facilities and hold facility details' do
@dmvfacilities.create_facilities(@mo_dmv_office_locations)
expect(@dmvfacilities.facilities.length).to eq(174)
expect(@dmvfacilities.facilities[1].name).to eq("High Ridge")
expect(@dmvfacilities.facilities[0].address).to eq("2009 Plaza Dr.")
expect(@dmvfacilities.facilities[2].phone).to eq("(660) 665-0292")
end
end

describe "#adds all facilities" do
it "can add facilities from all states at once" do
mo_count = @mo_dmv_office_locations.count
ny_count = @ny_dmv_office_locations.count
co_count = @co_dmv_office_locations.count

@dmvfacilities.create_facilities(@mo_dmv_office_locations)
expect(@dmvfacilities.facilities.length).to eq(mo_count)

@dmvfacilities.create_facilities(@ny_dmv_office_locations)
expect(@dmvfacilities.facilities.length).to eq(mo_count + ny_count)

@dmvfacilities.create_facilities(@co_dmv_office_locations)
expect(@dmvfacilities.facilities.length).to eq(mo_count + ny_count + co_count)

end
end
end
9 changes: 9 additions & 0 deletions spec/dmv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,13 @@
expect(@dmv.facilities_offering_service('Road Test')).to eq([@facility_2, @facility_3])
end
end

# describe '#add facilities API' do
# it 'can add available facilities from an API' do
# co_dmv_office_locations = DmvDataService.new.co_dmv_office_locations
# expect(@dmv.facilities).to eq([])
# @dmv.add_facility(co_dmv_office_locations)
# expect(@dmv.facilities.length).to eq(1)
# end
# end
end
81 changes: 81 additions & 0 deletions spec/facility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
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'})
@cruz = Vehicle.new({vin_1_10: '123456789abcdefgh', model_year: "2012", make: 'Chevrolet', model: 'Cruz', engine: :ice} )
@bolt = Vehicle.new({vin_1_10: '987654321abcdefgh', model_year: "2019", make: 'Chevrolet', model: 'Bolt', engine: :ev} )
@camaro = Vehicle.new({vin_1_10: '1a2b3c4d5e6f', model_year: "1969", make: 'Chevrolet', model: 'Camaro', engine: :ice} )
end
describe '#initialize' do
it 'can initialize' do
Expand All @@ -23,4 +26,82 @@
expect(@facility.services).to eq(['New Drivers License', 'Renew Drivers License', 'Vehicle Registration'])
end
end

describe '#register vehicle' do
it 'can register a vehicle' do
@facility.register_vehicle(@cruz)
expect(@facility.registered_vehicles).to eq([@cruz])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also want to make sure that the registration date is set when this method is called!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes gotcha! Missed that!

end
end

describe '#check registered vehicles' do
it 'has an array of vehicles' do
@facility.register_vehicle(@bolt)
@facility.register_vehicle(@camaro)
expect(@facility.registered_vehicles).to eq([@bolt, @camaro])
end
end

describe '#check fees' do
it 'has a value of collected fees' do
@facility.register_vehicle(@cruz)
@facility.register_vehicle(@bolt)
@facility.register_vehicle(@camaro)
expect(@facility.collected_fees).to eq(325)
end
end

describe "#administer_written_test" do
it "sets written value to true in registrant license data" do
registrant_1 = Registrant.new('Bruce', 18, true )
registrant_2 = Registrant.new('Penny', 15 )
registrant_3 = Registrant.new('Tucker', 15 )
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_1.add_service('Written Test')
facility_1.administer_written_test(registrant_1)

expect(registrant_1.license_data[:written]).to eq(true)
end
end

describe "#administer_road_test" do
it "sets license value to true in registrant license data" do
registrant_1 = Registrant.new('Bruce', 18, true )
registrant_2 = Registrant.new('Penny', 15 )
registrant_3 = Registrant.new('Tucker', 15 )
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_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)

expect(registrant_1.license_data[:license]).to eq(true)
end
end

describe "#renew_drivers_license" do
it "sets renewed value to true in registrant license data" do
registrant_1 = Registrant.new('Bruce', 18, true )
registrant_2 = Registrant.new('Penny', 15 )
registrant_3 = Registrant.new('Tucker', 15 )
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_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_drivers_license(registrant_1)
expect(registrant_1.license_data[:renewed]).to eq(true)
end
end


end
Loading