lib/progress.rb in progress-0.2.2 vs lib/progress.rb in progress-0.3.0

- old
+ new

@@ -8,10 +8,15 @@ module InstanceMethods # :nodoc: attr_accessor :title, :current, :total attr_reader :current_step def initialize(title, total) + if title.is_a?(Numeric) && total.nil? + title, total = nil, title + elsif total.nil? + total = 1 + end total = Float(total) @title, @current, @total = title, 0.0, total == 0.0 ? 1.0 : total end def step_if_blank @@ -60,11 +65,11 @@ # end # ==== To output progress as lines (not trying to stay on line) # Progress.lines = true # ==== To force highlight # Progress.highlight = true - def start(title, total = 1) + def start(title = nil, total = nil) levels << new(title, total) print_message(true) if block_given? begin yield @@ -150,11 +155,11 @@ messages = [] inner = 0 levels.reverse.each do |l| current = l.to_f(inner) value = current == 0 ? '......' : "#{'%5.1f' % (current * 100.0)}%" - messages << "#{l.title}: #{!highlight? || value == '100.0%' ? value : "\e[1m#{value}\e[0m"}" + messages << "#{"#{l.title}: " if l.title}#{!highlight? || value == '100.0%' ? value : "\e[1m#{value}\e[0m"}" inner = current end message = messages.reverse * ' > ' unless lines? @@ -179,10 +184,10 @@ require 'progress/enumerable' require 'progress/integer' # like Pathname module Kernel - def Progress(title, total = 1, &block) + def Progress(title = nil, total = nil, &block) Progress.start(title, total, &block) end private :Progress end