Created
September 4, 2013 00:54
-
-
Save steven-ferguson/6431548 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parcel | |
def initialize(weight, height, width, length) | |
@weight = weight | |
@height = height | |
@width = width | |
@length = length | |
@dimensional_weight = (@length * @width * @height)/ 166 | |
end | |
def dimensional_weight | |
@dimensional_weight | |
end | |
def cost_to_ship | |
if @weight > @dimensional_weight | |
@weight * 5 | |
else | |
@dimensional_weight * 5 | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "./lib/parcels" | |
def main_menu | |
puts "Please enter weight in pounds of package" | |
weight = gets.to_i | |
puts "Please enter height in inches" | |
height = gets.to_i | |
puts "Please enter width in inches" | |
width = gets.to_i | |
puts "Please enter length in inches" | |
length = gets.to_i | |
parcel = Parcel.new(weight, height, width, length) | |
puts "The cost to ship your package is $#{parcel.cost_to_ship}." | |
end | |
main_menu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
require 'parcels' | |
describe Parcel do | |
it "initializes with a weight, height, width and length" do | |
test_parcel = Parcel.new(100, 4, 4, 4) | |
test_parcel.should be_an_instance_of Parcel | |
end | |
it "has a dimensional weight" do | |
test_parcel = Parcel.new(100, 10, 10, 10) | |
test_parcel.dimensional_weight.should eq 6 | |
end | |
it "takes the dimensions and weight of the parcel and calculates cost to ship" do | |
test_parcel = Parcel.new(5,10,10,10) | |
test_parcel.cost_to_ship.should eq 30 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment