Thomascountz
6/11/2018 - 6:52 PM

Listing 6.5 - 99 Bottles of OOP

Listing 6.5 - 99 Bottles of OOP

# https://github.com/sandimetz/99bottles/blob/862f37346dfa8a9630c2ace0423e59c207a9f3f8/lib/bottles.rb
class BottleNumber
  attr_reader :number
  def initialize(number)
    @number = number
  end

  def to_s
    "#{quantity} #{container}"
  end

  def container
    if number == 1
      "bottle"
    else
      "bottles"
    end
  end

  def quantity
    if number == 0
      "no more"
    else
      number.to_s
    end
  end

  def action
    if number == 0
      "Go to the store and buy some more"
    else
      "Take #{pronoun} down and pass it around"
    end
  end

  def pronoun
    if number == 1
      "it"
    else
      "one"
    end
  end

  def successor
    if number == 0
      99
    else
      number - 1
    end
  end
end