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

Zion Mekonnen #613

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
arm64-darwin-24

DEPENDENCIES
faraday
Expand Down
3 changes: 2 additions & 1 deletion lib/dmv.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Dmv

attr_reader :facilities
def initialize
@facilities = []
end
Expand All @@ -9,7 +10,7 @@ def add_facility(facility)
end

def facilities_offering_service(service)
@facilities.find do |facility|
@facilities.select do |facility|
facility.services.include?(service)
end
end
Expand Down
40 changes: 33 additions & 7 deletions lib/facility.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
class Facility
attr_reader :name, :address, :phone, :services
attr_reader :name, :address, :phone, :services, :registered_vehicles, :plate_type, :registration_cost, :collected_fees

def initialize(name, address, phone)
@name = name
@address = address
@phone = phone
def initialize (facility_hash)
@name = facility_hash[:name]
@address = facility_hash[:address]
@phone = facility_hash[:phone]
@services = []
@registered_vehicles = []
@collected_fees = 0
end

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




def register_vehicle(vehicle)
binding.pry
if vehicle.antique?
vehicle.update_plate_type(:antique)
@collected_fees += 25
elsif vehicle.electric_vehicle?
vehicle.update_plate_type(:ev)
@collected_fees += 200
else
vehicle.update_plate_type(:regular)
@collected_fees += 100

end
binding.pry
@registration_date = Date.today

@registered_vehicles << vehicle
end

end

22 changes: 22 additions & 0 deletions lib/registrant.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Registrant
attr_reader :name, :age, :permit, :license_data

def initialize(name, age, permit = false)
@name = name
@age = age
@permit = permit
@license_data = {:written=>false, :license=>false, :renewed=>false}
end

def permit?
@permit
end

def earn_permit
@permit = true
end

end



19 changes: 17 additions & 2 deletions lib/vehicle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,36 @@ class Vehicle
:year,
:make,
:model,
:engine
:engine,
:plate_type,
:antique,
:register_date

Choose a reason for hiding this comment

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

Make sure you name your attr_readers with the same name as your instance variable that it is reading. In this case, it should be :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]
@registration_date = nil
@plate_type = nil
end

def update_registration_date
@registration_date = Date.today
end

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

def electric_vehicle?
@engine == :ev
end

def update_plate_type(type)
@plate_type = type
end

end
102 changes: 102 additions & 0 deletions spec/facility_services.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
require 'spec_helper'
require 'RSpec'

RSpec.describe Facility do
it 'exists' do
facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'})
facility_2 = Facility.new({name: 'DMV Northeast Branch', address: '4685 Peoria Street Suite 101 Denver CO 80239', phone: '(720) 865-4600'})

expect(facility_1).to be_an_instance_of(Facility)
expect(facility_2).to be_an_instance_of(Facility)
end

describe Vehicle do
it 'exists' do
cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice})
bolt = Vehicle.new({vin: '987654321abcdefgh', year: 2019, make: 'Chevrolet', model: 'Bolt', engine: :ev})
camaro = Vehicle.new({vin: '1a2b3c4d5e6f', year: 1969, make: 'Chevrolet', model: 'Camaro', engine: :ice})

expect(cruz).to be_an_instance_of(Vehicle)
expect(bolt).to be_an_instance_of(Vehicle)
expect(camaro).to be_an_instance_of(Vehicle)
end
end

# it "adds new service" do
# facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'})
# facility_1.add_service('Vehicle Registration')

# expect(facility_1.services).to include('Vehicle Registration')
# end

# it 'returns nil for cruz registration date' do
# cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice})

# expect(cruz.registration_date).to eq(nil)
#end

# it 'returns [] for registered vehicles' do
# facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'})

# expect(facility_1.registered_vehicles).to eq([])

# end

# it 'returns [] for collected fees' do
# facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'})

# expect(facility_1.collected_fees).to eq(0)

# end

# it 'registers a vehicle' do
# facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'})
# cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice})

# expect(facility_1.register_vehicle(cruz)).to include(cruz)
#end
it 'returns cruz registration date' do
facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'})
cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice})

facility_1.register_vehicle(cruz)


expect(cruz.registration_date).to eq(Date.today)
end

it "return plate type for cruz" do
facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'})
cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice})

facility_1.register_vehicle(cruz)

expect(cruz.plate_type).to eq(:regular)
end

it 'a vehicle has been registered' do
facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'})
cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice})

facility_1.register_vehicle(cruz)
expect(facility_1.registered_vehicles).to include(cruz)

end

it "updates collected fees when vehicle is registered" do
facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'})
cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice})

facility_1.register_vehicle(cruz)
expect(facility_1.collected_fees).to eq(100)
end






end



30 changes: 30 additions & 0 deletions spec/facility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
RSpec.describe Facility do
before(:each) do
@facility = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'})
@facility_1 = Facility.new({name: 'DMV Tremont Branch', address: '2855 Tremont Place Suite 118 Denver CO 80205', phone: '(720) 865-4600'})
@facility_2 = Facility.new({name: 'DMV Northeast Branch', address: '4685 Peoria Street Suite 101 Denver CO 80239', phone: '(720) 865-4600'})
@cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice} )
@bolt = Vehicle.new({vin: '987654321abcdefgh', year: 2019, make: 'Chevrolet', model: 'Bolt', engine: :ev} )
@camaro = Vehicle.new({vin: '1a2b3c4d5e6f', year: 1969, make: 'Chevrolet', model: 'Camaro', engine: :ice} )
end

describe '#initialize' do
it 'can initialize' do
expect(@facility).to be_an_instance_of(Facility)
Expand All @@ -21,6 +27,30 @@
@facility.add_service('Renew Drivers License')
@facility.add_service('Vehicle Registration')
expect(@facility.services).to eq(['New Drivers License', 'Renew Drivers License', 'Vehicle Registration'])
expect(@facility_1.add_service('Vehicle Registration')).to eq(['Vehicle Registration'])
end
end
it "returns [] for registered vehicles" do
expect(@facility_1.registered_vehicles).to eq([])

end

it 'returns 0 for collected fees' do
expect(@facility_1.collected_fees).to eq(0)
end

it "can register a vehicle" do
expect(@facility_1.register_vehicle(@cruz)).to eq([@cruz])
end

it 'updates registration date' do
today = Date.today
expect(@cruz.registration_date).to eq(nil)
@facility_1.register_vehicle(@cruz)
expect(@cruz.registration_date).to eq(today)
end




end
42 changes: 42 additions & 0 deletions spec/registrant_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require './lib/registrant'
require 'spec_helper'

RSpec.describe Registrant do
it "exists" do
registrant_1 = Registrant.new('Bruce', 18, true)
registrant_2 = Registrant.new('Penny', 15)

expect(registrant_1).to be_an_instance_of(Registrant)
expect(registrant_2).to be_an_instance_of(Registrant)
end

it 'returns attributes registrant 1' do
registrant_1 = Registrant.new('Bruce', 18, true)

expect(registrant_1.name).to eq("Bruce")
expect(registrant_1.age).to eq(18)
expect(registrant_1.permit?).to eq(true)
expect(registrant_1.license_data).to eq({:written=>false, :license=>false, :renewed=>false})
end

it 'returns attributes registrant 2' do
registrant_2 = Registrant.new('Penny', 15)

expect(registrant_2.name).to eq("Penny")
expect(registrant_2.age).to eq(15)
expect(registrant_2.license_data).to eq({:written=>false, :license=>false, :renewed=>false})
end

it "returns if permit is earned" do

Choose a reason for hiding this comment

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

This is a great test!

registrant_1 = Registrant.new('Bruce', 18, true)
registrant_2 = Registrant.new('Penny', 15)

expect(registrant_2.permit?).to eq(false)
registrant_1.earn_permit
expect(registrant_1.permit?).to eq(true)

end

end


1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
require './lib/facility'
require './lib/vehicle'
require './lib/dmv_data_service'
require './lib/registrant'
7 changes: 7 additions & 0 deletions spec/vehicle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@
expect(@camaro.electric_vehicle?).to eq(false)
end
end
it 'returns nil for cruz registration date' do
cruz = Vehicle.new({vin: '123456789abcdefgh', year: 2012, make: 'Chevrolet', model: 'Cruz', engine: :ice})

expect(cruz.registration_date).to eq(nil)
end


Choose a reason for hiding this comment

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

You want to add tests for any methods that you create. It looks like we are missing tests for update_registration_date and update_plate_type

end