Class: Progress
- Inherits:
-
Object
- Object
- Progress
- Defined in:
- lib/progress.rb
Instance Method Summary collapse
- #finish!(message_addition = "") ⇒ Object
-
#initialize(message, time = nil) ⇒ Progress
constructor
ANSI escape code to clear line from cursor to end of line “e” is an alternative to “033” cf.
- #progress(num, message_addition = "") ⇒ Object (also: #update)
Constructor Details
#initialize(message, time = nil) ⇒ Progress
ANSI escape code to clear line from cursor to end of line “e” is an alternative to “033” cf. en.wikipedia.org/wiki/ANSI_escape_code
6 7 8 9 10 |
# File 'lib/progress.rb', line 6 def initialize(, time = nil) @message = @time = time ? time : Time.now @reset = "\r\e[0K" end |
Instance Method Details
#finish!(message_addition = "") ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/progress.rb', line 17 def finish!( = "") time = Time.now - @time = @message + str = "#{@reset} #{}" + "100%".rjust(60-.length) print str + "Took: #{"%.2f" % time} sec.\n".rjust(100-str.length) $stdout.flush end |
#progress(num, message_addition = "") ⇒ Object Also known as: update
11 12 13 14 15 16 |
# File 'lib/progress.rb', line 11 def progress(num, = "") = @message+ # reset lines print "#{@reset} #{}" + "#{num}%".rjust(60-.length) $stdout.flush end |