Created
May 17, 2013 02:54
-
-
Save abrongersma/5596624 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Package | |
| attr_accessor :contents | |
| attr_reader :from_location | |
| attr_accessor :to_location | |
| attr_reader :current_location | |
| attr_reader :stops | |
| def self.delivery_est(from, to) | |
| if from == "San Francisco, CA" && to == "Chicago, IL" | |
| 2 | |
| elsif from == "Austin, TX" && to == "New York, NY" | |
| 2 | |
| elsif from == "San Diego, CA" && to == "New York, NY" | |
| 3 | |
| end | |
| end | |
| def self.new_packages(contents, from_loc, to_loc) | |
| delivery = self.delivery_est(from_loc, to_loc) | |
| a = Package.new(contents[0], from_loc, to_loc, delivery) | |
| b = Package.new(contents[1], from_loc, to_loc, delivery) | |
| [a,b] | |
| end | |
| def initialize(contents, from_loc, to_loc, del_est) | |
| @contents = contents | |
| self.from_location = from_loc | |
| @to_location = to_loc | |
| @delivery_est = del_est | |
| end | |
| def from_location=(new_loc) | |
| @from_location = new_loc | |
| @stops = [new_loc] | |
| end | |
| def delivered? | |
| @current_location == @to_location | |
| end | |
| def checked_in_at(location) | |
| @stops << location | |
| @current_location = location | |
| end | |
| def estimated_delivery | |
| @delivery_est - @stops.length | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment