Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions beer_song.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class String
def pluralize(count)
string = self.to_s
word = (count > 1 || count == 0) ? "#{string}s" : string
count = "no more" if count == 0
"#{count} #{word}"
end
end

class BeerSong

def verse(line_number)
current_verse = Verse.new(line_number)
current_verse.first_sentence << current_verse.second_sentence
end

def verses(a, b)
(b..a).map do |index|
verse(index)
end.reverse.join("\n")
end

def lyrics
verses(99, 0)
end

end
10 changes: 2 additions & 8 deletions beer_song_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
gem 'minitest', '>= 5.0.0'
require 'minitest/autorun'
require_relative 'beer_song'
require_relative 'book_keeping'
require_relative 'verse'

# rubocop:disable Metrics/LineLength
class BeerSongTest < Minitest::Test
Expand All @@ -12,35 +14,30 @@ def test_the_first_verse
end

def test_another_verse
skip
expected = "3 bottles of beer on the wall, 3 bottles of beer.\n" \
"Take one down and pass it around, 2 bottles of beer on the wall.\n"
assert_equal expected, BeerSong.new.verse(3)
end

def test_verse_2
skip
expected = "2 bottles of beer on the wall, 2 bottles of beer.\n" \
"Take one down and pass it around, 1 bottle of beer on the wall.\n"
assert_equal expected, BeerSong.new.verse(2)
end

def test_verse_1
skip
expected = "1 bottle of beer on the wall, 1 bottle of beer.\n" \
"Take it down and pass it around, no more bottles of beer on the wall.\n"
assert_equal expected, BeerSong.new.verse(1)
end

def test_verse_0
skip
expected = "No more bottles of beer on the wall, no more bottles of beer.\n" \
"Go to the store and buy some more, 99 bottles of beer on the wall.\n"
assert_equal expected, BeerSong.new.verse(0)
end

def test_a_couple_verses
skip
expected = "99 bottles of beer on the wall, 99 bottles of beer.\n" \
"Take one down and pass it around, 98 bottles of beer on the wall.\n" \
"\n" \
Expand All @@ -50,7 +47,6 @@ def test_a_couple_verses
end

def test_a_few_verses
skip
expected = "2 bottles of beer on the wall, 2 bottles of beer.\n" \
"Take one down and pass it around, 1 bottle of beer on the wall.\n" \
"\n" \
Expand All @@ -63,7 +59,6 @@ def test_a_few_verses
end

def test_the_whole_song # rubocop:disable Metrics/MethodLength
skip
expected = <<-SONG
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.
Expand Down Expand Up @@ -375,7 +370,6 @@ def test_the_whole_song # rubocop:disable Metrics/MethodLength
#
# Define a constant named VERSION inside of BookKeeping.
def test_bookkeeping
skip
assert_equal 2, BookKeeping::VERSION
end
end
3 changes: 3 additions & 0 deletions book_keeping.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class BookKeeping
VERSION = 2.freeze
end
21 changes: 21 additions & 0 deletions verse.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Verse
def initialize(line_number)
@line_number = line_number
end
attr_reader :line_number

def first_sentence
first_word = "bottle".pluralize(line_number)
first_word = first_word.capitalize if line_number == 0
"#{first_word} of beer on the wall, #{"bottle".pluralize(line_number)} of beer.\n" \
end

def second_sentence
if line_number == 0
"Go to the store and buy some more, 99 bottles of beer on the wall.\n"
else
one_word = line_number == 1 ? "it" : "one"
"Take #{one_word} down and pass it around, #{"bottle".pluralize(line_number - 1)} of beer on the wall.\n"
end
end
end