diff --git a/bike.rb b/bike.rb index f8073dd..790ac7a 100644 --- a/bike.rb +++ b/bike.rb @@ -1,11 +1,10 @@ # Bike +require_relative 'bike_cargo' class Bike - STANDARD_WEIGHT = 200 # lbs - MAX_CARGO_ITEMS = 10 - attr_accessor :id, :color, :price, :weight, :rented, :cargo_contents + attr_accessor :id, :color, :price, :weight, :rented, :cargo_contents, :bike_cargo def initialize(id, color, price, weight = STANDARD_WEIGHT, rented = false) @id = id @@ -13,27 +12,10 @@ def initialize(id, color, price, weight = STANDARD_WEIGHT, rented = false) @price = price @weight = weight @rented = rented - @cargo_contents = [] + @bike_cargo = BikeCargo.new end def rent! self.rented = true - end - - def add_cargo(item) - self.cargo_contents << item - end - - def remove_cargo(item) - self.cargo_contents.remove(item) - end - - def pannier_capacity - MAX_CARGO_ITEMS - end - - def pannier_remaining_capacity - MAX_CARGO_ITEMS - self.cargo_contents.size - end - + end end diff --git a/bike_cargo.rb b/bike_cargo.rb new file mode 100644 index 0000000..77b7392 --- /dev/null +++ b/bike_cargo.rb @@ -0,0 +1,27 @@ +class BikeCargo + MAX_CARGO_ITEMS = 10 + + attr_accessor :cargo_contents + + def initialize + @cargo_contents = [] + end + + def add_cargo(item) + if pannier_remaining_capacity > 0 + @cargo_contents << item + end + end + + def remove_cargo(item) + @cargo_contents.remove(item) + end + + def pannier_capacity + MAX_CARGO_ITEMS + end + + def pannier_remaining_capacity + MAX_CARGO_ITEMS - @cargo_contents.size + end +end \ No newline at end of file diff --git a/main.rb b/main.rb index 3d82192..a27e591 100644 --- a/main.rb +++ b/main.rb @@ -1,13 +1,14 @@ -!# /usr/bin/env ruby +# /usr/bin/env ruby require_relative 'bike' +require_relative 'bike_cargo' bike = Bike.new(1, :pink, 99.99) -bike.add_cargo(:apples) -bike.add_cargo(:water) -bike.add_cargo(:repair_kit) +bike.bike_cargo.add_cargo(:apples) +bike.bike_cargo.add_cargo(:water) +bike.bike_cargo.add_cargo(:repair_kit) -puts "Space for #{bike.pannier_remaining_capacity} items left." +puts "Space for #{bike.bike_cargo.pannier_remaining_capacity} items left." bike.rent!