Class: ProgressBar::Console

Inherits:
Base
  • Object
show all
Defined in:
lib/progress-bar.rb

Instance Attribute Summary

Attributes inherited from Base

#error, #i, #max, #start, #text

Instance Method Summary collapse

Methods inherited from Base

#done_dur, #done_rel, #finish, #increment!, #total_dur

Constructor Details

#initialize(*a) ⇒ Console

Returns a new instance of Console.



54
55
56
57
# File 'lib/progress-bar.rb', line 54

def initialize *a
	super *a
	change_text
end

Instance Method Details

#change_errorObject



74
75
76
77
# File 'lib/progress-bar.rb', line 74

def change_error
	STDERR.printf "\r\e[J%s\n", error
	change_text
end

#change_textObject Also known as: change_progress



67
68
69
70
71
# File 'lib/progress-bar.rb', line 67

def change_text
	l = (100.0*i/max).to_i
	dd, td = done_dur, total_dur
	STDOUT.printf "\r\e[J%s / %s [%s>%s] %s", format_time(dd), format_time(td), '='*l, ' '*(100-l), text
end

#format_time(t) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/progress-bar.rb', line 59

def format_time t
	if t.finite?
		sprintf "%02d:%02d:%02d", t/1.hour, t/1.minute % 1.hour, t % 1.minute
	else
		"--:--:--"
	end
end