Class: Console::Measure
- Inherits:
-
Object
- Object
- Console::Measure
- Defined in:
- lib/console/measure.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #average_duration ⇒ Object
- #duration ⇒ Object
- #estimated_remaining_time ⇒ Object
- #increment(amount = 1) ⇒ Object
-
#initialize(output, subject, total = 0) ⇒ Measure
constructor
A new instance of Measure.
- #mark(*arguments) ⇒ Object
- #progress ⇒ Object
- #remaining ⇒ Object
- #resize(total) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(output, subject, total = 0) ⇒ Measure
Returns a new instance of Measure.
23 24 25 26 27 28 29 30 31 |
# File 'lib/console/measure.rb', line 23 def initialize(output, subject, total = 0) @output = output @subject = subject @start_time = Time.now @current = 0 @total = total end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
35 36 37 |
# File 'lib/console/measure.rb', line 35 def current @current end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
33 34 35 |
# File 'lib/console/measure.rb', line 33 def subject @subject end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
37 38 39 |
# File 'lib/console/measure.rb', line 37 def total @total end |
Instance Method Details
#average_duration ⇒ Object
51 52 53 54 55 |
# File 'lib/console/measure.rb', line 51 def average_duration if @current > 0 duration / @current end end |
#duration ⇒ Object
39 40 41 |
# File 'lib/console/measure.rb', line 39 def duration Time.now - @start_time end |
#estimated_remaining_time ⇒ Object
57 58 59 60 61 |
# File 'lib/console/measure.rb', line 57 def estimated_remaining_time if average_duration = self.average_duration average_duration * remaining end end |
#increment(amount = 1) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/console/measure.rb', line 63 def increment(amount = 1) @current += amount @output.info(@subject, self) {Event::Progress.new(@current, @total)} return self end |
#mark(*arguments) ⇒ Object
79 80 81 |
# File 'lib/console/measure.rb', line 79 def mark(*arguments) @output.info(@subject, *arguments) end |
#progress ⇒ Object
43 44 45 |
# File 'lib/console/measure.rb', line 43 def progress @current.to_f / @total.to_f end |
#remaining ⇒ Object
47 48 49 |
# File 'lib/console/measure.rb', line 47 def remaining @total - @current end |
#resize(total) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/console/measure.rb', line 71 def resize(total) @total = total @output.info(@subject, self) {Event::Progress.new(@current, @total)} return self end |
#to_s ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/console/measure.rb', line 83 def to_s if estimated_remaining_time = self.estimated_remaining_time "#{@current}/#{@total} completed in #{self.formatted_duration self.duration}, #{self.formatted_duration estimated_remaining_time} remaining." else "#{@current}/#{@total} completed, waiting for estimate..." end end |