Skip to content

Instantly share code, notes, and snippets.

@pjlowry
Created February 11, 2013 22:50
Show Gist options
  • Save pjlowry/4758367 to your computer and use it in GitHub Desktop.
Save pjlowry/4758367 to your computer and use it in GitHub Desktop.
Shipping cost estimator.
class Parcel
attr_accessor :new_hash
def initialize
hash_empty = Hash.new
@hash_empty = hash_empty
end
def new_box(length, width, height, weight) #inches and lbs
@hash_empty = {"length" => length, "width" => width, "height" => height, "weight" => weight}
if @hash_empty["length"] <= 12 && @hash_empty["width"] <= 6 && @hash_empty["height"] <= 6
result = 5 + @hash_empty["weight"].ceil
@result = result
tax = @result * 0.08
@tax = tax
total = @result + @tax
@total = total
puts "$5 dollar flat rate box plus a dollar per pound comes to $ #{@result}.00"
puts "\n"
puts "\t" "subtotal: $ #{@result}.00"
puts "\t" "tax : $ #{@tax}"
puts "\t" "total : $ #{@total}"
elsif @hash_empty["length"] <= 24 && @hash_empty["width"] <= 12 && @hash_empty["height"] <= 12
result = 10 + @hash_empty["weight"].ceil
@result = result
tax = @result * 0.08
@tax = tax
total = @result + @tax
@total = total
puts "$10 dollar flat rate box plus a dollar per pound comes to $ #{@result}.00"
puts "\n"
puts "\t" "subtotal: $ #{@result}.00"
puts "\t" "tax : $ #{@tax}"
puts "\t" "total : $ #{@total}"
elsif @hash_empty["length"] <= 48 && @hash_empty["width"] <= 24 && @hash_empty["height"] <= 24
result = 15 + @hash_empty["weight"].ceil
@result = result
tax = @result * 0.08
@tax = tax
total = @result + @tax
@total = total
puts "$15 dollar flat rate box plus a dollar per pound comes to $ #{@result}.00"
puts "\n"
puts "\t" "subtotal: $ #{@result}.00"
puts "\t" "tax : $ #{@tax}"
puts "\t" "total : $ #{@total}"
elsif @hash_empty["length"] > 48 || @hash_empty["width"] > 24 || @hash_empty["height"] > 24
"Sorry we don't have any boxes that big. Go to FedEx"
elsif @hash_empty["weight"] > 20
"Please contact us directly at customer service 1(888) 888-8888."
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment