Created
August 15, 2015 03:50
-
-
Save srabuini/9d28bb5be8c2e8f0a7b1 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 WestheimerRule | |
UNITS = %i(seconds minutes hours days weeks months years lustra decades | |
centuries millennniums) | |
def initialize(time:, unit:) | |
@time = time | |
@unit = unit | |
end | |
def estimate | |
"#{2 * @time} #{next_unit}" | |
end | |
private | |
def next_unit | |
UNITS[next_unit_index] | |
end | |
def next_unit_index | |
unit_index + 1 | |
end | |
def unit_index | |
UNITS.index(@unit) | |
end | |
end | |
WestheimerRule.new(time: 2, unit: :weeks).estimate | |
# => "4 months" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment