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

Rig Freyr #5

Open
wants to merge 6 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
37 changes: 37 additions & 0 deletions lib/park.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class Park
attr_reader :name, :price, :vehicles, :passengers

def initialize(name, price)
@name = name
@price = price
@vehicles = []
@passengers = []
end

def add_vehicle(course)
@vehicles << course
course.passengers.each {|passenger|
@passengers << passenger
}
return @vehicles
end

def revenue
return (price * (@passengers.select{|passenger| passenger.adult?}.length))
end

def patron_names
return @passengers.map{|passenger| passenger.name}.sort
end

def minors
minors = @passengers.select{|passenger| passenger.adult? == false}
return minors.map{|minor| minor.name}.sort
end

def adults
adults = @passengers.select{|passenger| passenger.adult?}
return adults.map{|adult| adult.name}.sort
end

end
23 changes: 23 additions & 0 deletions lib/passenger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Passenger
attr_reader :name, :age


def initialize(passenger_details)
@name = passenger_details["name"]
@age = passenger_details["age"]
@driver = false
end

def adult?
age >= 18 ? true : false
end

def driver?
return @driver
end

def drive
@driver = true
end

end
28 changes: 28 additions & 0 deletions lib/vehicle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Vehicle
attr_reader :year, :make, :model, :passengers

def initialize(year, make, model)
@year = year
@make = make
@model = model
@passengers = []
@speeding = false
end

def speeding?
return @speeding
end

def speed
@speeding = true
end

def add_passenger(passenger)
@passengers << passenger
end

def num_adults
return passengers.select{|passenger| passenger.adult?}.length
end

end
131 changes: 131 additions & 0 deletions spec/park_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
require './lib/passenger'
require './lib/vehicle'
require './lib/park'
require 'rspec'

describe Park do
before do
@charlie = Passenger.new({"name" => "Charlie", "age" => 18})
@jude = Passenger.new({"name" => "Jude", "age" => 20})
@taylor = Passenger.new({"name" => "Taylor", "age" => 12})

@honda = Vehicle.new("2001", "Honda", "Civic")
@honda.add_passenger(@charlie)
@honda.add_passenger(@jude)
@honda.add_passenger(@taylor)

@lamar = Passenger.new({"name" => "Lamar", "age" => 38})
@debbie = Passenger.new({"name" => "Debbie", "age" => 36})

@toyota = Vehicle.new("2015", "Toyota", "4Runner")
@toyota.add_passenger(@lamar)
@toyota.add_passenger(@debbie)

@rick = Passenger.new({"name" => "Rick", "age" => 45})

@hyundai = Vehicle.new("2008", "Hyundai", "Sonata")
@hyundai.add_passenger(@rick)

@fester = Passenger.new({"name" => "Fester", "age" => 63})
@wednesday = Passenger.new({"name" => "Wednesday", "age" => 14})
@pugsley = Passenger.new({"name" => "Pugsley", "age" => 13})

@ford = Vehicle.new("1951", "Ford", "Model T")
@ford.add_passenger(@fester)
@ford.add_passenger(@wednesday)
@ford.add_passenger(@pugsley)

@yellowstone = Park.new("Yellowstone", 30)
end

describe '#initialize' do
it 'exists' do
expect(@yellowstone).to be_a(Park)
end

it 'has a name' do
expect(@yellowstone.name).to eq("Yellowstone")
end

it 'has a price' do
expect(@yellowstone.price).to eq(30)
end

it 'starts with an empty list of vehicles' do
expect(@yellowstone.vehicles).to eq([])
end

it 'starts with an empty list of passengers' do
expect(@yellowstone.passengers).to eq([])
end

end

describe '#add_vehicle' do
it 'can add a vehicle to the park' do
expect(@yellowstone.add_vehicle(@honda)).to eq([@honda])
end

it 'can list all the vehicles that entered the park' do
@yellowstone.add_vehicle(@honda)
@yellowstone.add_vehicle(@toyota)
@yellowstone.add_vehicle(@hyundai)
@yellowstone.add_vehicle(@ford)
expect(@yellowstone.vehicles).to eq([@honda, @toyota, @hyundai, @ford])
end

it 'can list all the passengers that entered the park' do
@yellowstone.add_vehicle(@honda)
@yellowstone.add_vehicle(@toyota)
expect(@yellowstone.passengers).to eq([@charlie, @jude, @taylor, @lamar, @debbie])
end
end

describe '#revenue' do
it 'can calculate revenue generated' do
@yellowstone.add_vehicle(@honda)
@yellowstone.add_vehicle(@toyota)
@yellowstone.add_vehicle(@hyundai)
@yellowstone.add_vehicle(@ford)

expect(@yellowstone.price).to eq(30)
expect(@yellowstone.adults.length).to eq(6)

expect(@yellowstone.revenue).to eq(180)
end
end

describe '#patron_names' do
it 'can provide an alphabetical list of patron names' do
@yellowstone.add_vehicle(@honda)
@yellowstone.add_vehicle(@toyota)
@yellowstone.add_vehicle(@hyundai)
@yellowstone.add_vehicle(@ford)

expect(@yellowstone.patron_names).to eq(["Charlie", "Debbie", "Fester", "Jude", "Lamar", "Pugsley", "Rick", "Taylor", "Wednesday"])
end
end

describe '#minors' do
it 'can provide an alphabetical list of all minors' do
@yellowstone.add_vehicle(@honda)
@yellowstone.add_vehicle(@toyota)
@yellowstone.add_vehicle(@hyundai)
@yellowstone.add_vehicle(@ford)

expect(@yellowstone.minors).to eq(["Pugsley", "Taylor", "Wednesday"])
end
end

describe '#adults' do
it 'can provide an alphabetical list of all adults' do
@yellowstone.add_vehicle(@honda)
@yellowstone.add_vehicle(@toyota)
@yellowstone.add_vehicle(@hyundai)
@yellowstone.add_vehicle(@ford)

expect(@yellowstone.adults).to eq(["Charlie", "Debbie", "Fester", "Jude", "Lamar", "Rick"])
end
end

end
49 changes: 49 additions & 0 deletions spec/passenger_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require './lib/passenger'
require 'rspec'

describe Passenger do
before do
@charlie = Passenger.new({"name" => "Charlie", "age" => 18})
@taylor = Passenger.new({"name" => "Taylor", "age" => 12})
end

describe '#initialize' do
it 'exists' do
expect(@charlie).to be_a(Passenger)
expect(@taylor).to be_a(Passenger)
end

it 'has a name' do
expect(@charlie.name).to eq("Charlie")
expect(@taylor.name).to eq("Taylor")
end

it 'has an age' do
expect(@charlie.age).to eq(18)
expect(@taylor.age).to eq(12)
end
end

describe '#adult?' do
it 'can check whether a passenger is an adult' do
expect(@charlie.adult?).to eq(true)
expect(@taylor.adult?).to eq(false)
end
end

describe '#driver?' do
it 'can check whether a passenger is the driver' do
expect(@charlie.driver?).to eq(false)
expect(@taylor.driver?).to eq(false)
end
end

describe '#drive' do
it 'can make a passenger the driver' do
expect(@charlie.driver?).to eq(false)
@charlie.drive
expect(@charlie.driver?).to eq(true)
end
end

end
76 changes: 76 additions & 0 deletions spec/vehicle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require './lib/passenger'
require './lib/vehicle'
require 'rspec'

describe Vehicle do
before do
@vehicle = Vehicle.new("2001", "Honda", "Civic")

@charlie = Passenger.new({"name" => "Charlie", "age" => 18})
@jude = Passenger.new({"name" => "Jude", "age" => 20})
@taylor = Passenger.new({"name" => "Taylor", "age" => 12})
end

describe '#initialize' do
it 'exists' do
expect(@vehicle).to be_a(Vehicle)
end

it 'has a year' do
expect(@vehicle.year).to eq("2001")
end

it 'has a make' do
expect(@vehicle.make).to eq("Honda")
end

it 'has a model' do
expect(@vehicle.model).to eq("Civic")
end

it 'starts with no passengers' do
expect(@vehicle.passengers).to eq([])
end
end

describe '#speeding?' do
it 'can check whether a vehicle is speeding' do
expect(@vehicle.speeding?).to eq(false)
end
end

describe '#speed' do
it 'can make a vehicle start speeding' do
expect(@vehicle.speeding?).to eq(false)

@vehicle.speed

expect(@vehicle.speeding?).to eq(true)
end
end

describe '#add_passenger' do
it 'can add passengers to a vehicle' do
@vehicle.add_passenger(@charlie)
@vehicle.add_passenger(@jude)
@vehicle.add_passenger(@taylor)

expect(@vehicle.passengers).to eq([@charlie, @jude, @taylor])
end
end

describe '#num_adults' do
it 'can track number of adults in a vehicle' do
@vehicle.add_passenger(@charlie)
@vehicle.add_passenger(@jude)
@vehicle.add_passenger(@taylor)

expect(@charlie.adult?).to eq(true)
expect(@jude.adult?).to eq(true)
expect(@taylor.adult?).to eq(false)

expect(@vehicle.num_adults).to eq(2)
end
end

end