module JobStatusGeneration
  def to_status
    rep = []

    rep << "Job #{ident} (#{url}):"

    if in_progress?
      rep << "In progress.  Downloaded #{mb_downloaded.round(2)} MB, #{error_count.to_i} errors encountered."
      rep << "See the ArchiveBot dashboard for more information."
    elsif completed?
      rep << "Archived to #{archive_url}."

      if (t = ttl)
        rep << "Eligible for rearchival in #{formatted_ttl(t)}."
      end
    elsif aborted?
      rep << "Job aborted."

      if (t = ttl)
        rep << "Eligible for rearchival in #{formatted_ttl(t)}."
      end
    end
  end

  private

  def mb_downloaded
    bytes_downloaded.to_f / (1000 * 1000)
  end

  def formatted_ttl(ttl)
    hr = ttl / 3600
    min = (ttl % 3600) / 60
    sec = (ttl % 3600) % 60

    "#{hr}h #{min}m #{sec}s"
  end
end

module JobStatusGeneration
  def to_status
    rep = []

    rep << "Job #{ident} (#{url}):"

    if in_progress?
      rep << "In progress.  Downloaded #{mb_downloaded.round(2)} MB, #{error_count.to_i} errors encountered."
      rep << "See the ArchiveBot dashboard for more information."
    elsif completed?
      rep << "WARC: #{archive_url}"

      if (t = ttl)
        rep << "Eligible for rearchival in #{formatted_ttl(t)}."
      end
    elsif aborted?
      rep << "Job aborted."

      if (t = ttl)
        rep << "Eligible for rearchival in #{formatted_ttl(t)}."
      end
    end
  end

  private

  def mb_downloaded
    bytes_downloaded.to_f / (1000 * 1000)
  end

  def formatted_ttl(ttl)
    hr = ttl / 3600
    min = (ttl % 3600) / 60
    sec = (ttl % 3600) % 60

    "#{hr}h #{min}m #{sec}s"
  end
end

Remove period at end of URL given in !status.
Remove period at end of URL given in !status.

Some IRC clients interpret the period as part of the URL, which can
cause retrieval errors.
