class Life_item
  # What's my time worth, not being able to do something else while I'm tending to maintaining the things that own me.
  @@value_of_time = nil

  @maintainers = nil
  attr_reader :maintainers

  def initialize(in_name, in_cost, in_value_of_time)
    @name, @cost, @maintainers, @@value_of_time = in_name, in_cost, [], in_value_of_time
  end

  def add_maintainer(in_name, in_cost, in_period, in_time_spent)
    @maintainers << Maintainer.new(in_name, in_cost, in_period, in_time_spent, @@value_of_time)
  end

  def to_s()
    s = <<EOS
Name = %s
Cost = $%.2f
EOS
    s_out = sprintf(s, @name, @cost)
    @maintainers.each { |maintainer| s_out += (maintainer.to_s) }
    s_out
  end
end

class Maintainer
  # period is in days
  # time_spent is in hours

  def initialize(in_name, in_cost, in_period, in_time_spent, in_value_of_time)
    @name, @cost, @period, @time_spent = in_name, in_cost, in_period, in_time_spent
    @value_of_time = in_value_of_time
  end

  def time_per_day()
    @time_spent / @period
  end

  def cost_per_day()
    @cost / @period
  end

  def to_s()
    s = <<EOS

   Name = %s
   Cost = $%.2f every %d day%s
   Time = %.2f hours
EOS
   sprintf(s, @name, @cost, @period, @period == 1 ? '' : 's', @time_spent)
   end
end