class DurationEstimate::TerminalFormatter

Format a status line for terminal.

Attributes

estimate[RW]

Reference to the estimate instance.

@return [DurationEstimate]

Public Class Methods

format(estimate) click to toggle source

Format a status line for terminal.

@return [String]

# File lib/duration_estimate/terminal_formatter.rb, line 12
def self.format(estimate)
  new(estimate).format
end
new(estimate) click to toggle source

Format a status line for terminal.

@param estimate [DurationEstimate] Reference to the estimate instance.

# File lib/duration_estimate/terminal_formatter.rb, line 19
def initialize(estimate)
  self.estimate = estimate
end

Public Instance Methods

format() click to toggle source

Format estimate as a string. Prevent trailing junk characters by setting fixed widths for things.

@return [String]

# File lib/duration_estimate/terminal_formatter.rb, line 27
def format
  [
    "#{items_done}/#{estimate.items_size}",
    "(#{percentage} %)",
    "#{estimate.ends_at.strftime('%H:%M:%S')},",
    "#{estimate.time_remaining}"
  ].join(' ')
end

Private Instance Methods

items_done() click to toggle source

Align the items_done number to the right.

@return [String]

# File lib/duration_estimate/terminal_formatter.rb, line 41
def items_done
  estimate.items_done.to_s.rjust(items_size_digits)
end
items_size_digits() click to toggle source

Number of digits for the items_size number.

@return [Fixnum]

# File lib/duration_estimate/terminal_formatter.rb, line 48
def items_size_digits
  estimate.items_size.to_s.size
end
percentage() click to toggle source

Format percentage number.

@return [String]

# File lib/duration_estimate/terminal_formatter.rb, line 55
def percentage
  Kernel.format('%6.02f', estimate.percentage)
end