Created
May 21, 2014 19:07
-
-
Save mpelzsherman/32cc3be03ec949712945 to your computer and use it in GitHub Desktop.
MPS' Bottles
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 Bottles | |
MAX_BOTTLE = 99 | |
MIN_BOTTLE = 0 | |
def song | |
verses(MAX_BOTTLE, MIN_BOTTLE) | |
end | |
def verses(high_bottle_number, low_bottle_number) | |
high_bottle_number.downto(low_bottle_number).map do |bottle_number| | |
verse(bottle_number) | |
end.join("\n") | |
end | |
def verse(bottle_number) | |
case bottle_number | |
when 0 | |
"No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, #{MAX_BOTTLE} bottles of beer on the wall.\n" | |
when 1 | |
"1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n" | |
else | |
"#{bottle_number} bottles of beer on the wall, #{bottle_number} bottles of beer.\nTake one down and pass it around, #{bottle_number-1} #{container_name(bottle_number-1)} of beer on the wall.\n" | |
end | |
end | |
def container_name(quantity) | |
quantity == 1 ? "bottle" : "bottles" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment