Advertisement
Guest User

Untitled

a guest
Oct 7th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.45 KB | None | 0 0
  1. class Bottles
  2.  
  3.     def verse(part)
  4.         "#{bottle(part)[0]} of beer on the wall, #{bottle(part)[1]} of beer.\n".capitalize() +
  5.         "#{part == 0 ? "Go to the store and buy some more" : "Take #{part == 1 ? "it" : "one"} down and pass it around"}" +
  6.         ", #{bottle(part)[2]} of beer on the wall.\n"
  7.     end
  8.  
  9.     def verses(first_verse, second_verse)
  10.         final_string = ""
  11.         array = build_array(first_verse, second_verse)
  12.         array.each_with_index do |part, index|
  13.             final_string += verse(part)
  14.             break if index == array.length - 1
  15.             final_string += "\n"
  16.         end
  17.         final_string
  18.     end
  19.  
  20.     def song
  21.         verses(99, 0);
  22.     end
  23.  
  24.     def build_array(start_num, end_num)
  25.         array = []
  26.         start = start_num
  27.         counter = 0
  28.         while start != end_num - 1
  29.             array[counter] = start
  30.             start = start - 1
  31.             counter = counter + 1
  32.         end
  33.         array
  34.     end
  35.  
  36.     def number_wheel(number)
  37.         return 99 if number == 0
  38.         number - 1
  39.     end
  40.  
  41.     def bottle(amount)
  42.         first = amount
  43.         second = amount
  44.         last = number_wheel(amount)
  45.        
  46.         [singular_or_plural(first), singular_or_plural(second), singular_or_plural(last)]
  47.     end
  48.  
  49.     def singular_or_plural(number)
  50.         return "no more bottles" if number == 0
  51.         number == 1 ? "#{number} bottle" : "#{number} bottles"
  52.     end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement