Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bottles of Beer on the Wall #1

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
37 changes: 37 additions & 0 deletions bottles/lib/bottles.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
class Bottles
def verse(n)
"#{prefix(n)}\n#{suffix(n)}\n"
end

def prefix(n)
if n > 0
"#{numberBottles(n)} of beer on the wall, #{numberBottles(n)} of beer."
else
"No more bottles of beer on the wall, no more bottles of beer."
end
end

def suffix(n)
if n == 0
"Go to the store and buy some more, 99 bottles of beer on the wall."
elsif n == 1
"Take it down and pass it around, no more bottles of beer on the wall."
else
"Take one down and pass it around, #{numberBottles(n - 1)} of beer on the wall."
end
end

def verses(start, finish)
start.downto(finish).map { |n| verse(n) }.join("\n") << "\n"
end

def numberBottles(n)
if n == 1
"#{n} bottle"
else
"#{n} bottles"
end
end

def sing
verses(99, 0)
end
end
6 changes: 0 additions & 6 deletions bottles/spec/bottles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,31 @@
end

it "can sing another typical verse" do
skip
expected = "3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n"
expect( song.verse(3) ).to eq( expected )
end

it "can sing about 1 bottle" do
skip
expected = "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"
expect( song.verse(1) ).to eq( expected )
end

it "can sing about 2 bottles" do
skip
expected = "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n"
expect( song.verse(2) ).to eq( expected )
end

it "can sing about no more bottles" do
skip
expected = "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n"
expect( song.verse(0) ).to eq( expected )
end

it "can string a few verses together" do
skip
expected = "8 bottles of beer on the wall, 8 bottles of beer.\nTake one down and pass it around, 7 bottles of beer on the wall.\n\n7 bottles of beer on the wall, 7 bottles of beer.\nTake one down and pass it around, 6 bottles of beer on the wall.\n\n6 bottles of beer on the wall, 6 bottles of beer.\nTake one down and pass it around, 5 bottles of beer on the wall.\n\n"
expect( song.verses(8, 6) ).to eq( expected )
end

it "can sing the whole song" do
skip
expect( song.sing ).to eq( song.verses(99, 0) )
end
end