Class: Traquitana::Bar
- Inherits:
-
Object
- Object
- Traquitana::Bar
- Defined in:
- lib/bar.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#name ⇒ Object
Returns the value of attribute name.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
- #indicator(current) ⇒ Object
-
#initialize ⇒ Bar
constructor
A new instance of Bar.
- #reset ⇒ Object
- #update(current) ⇒ Object
Constructor Details
#initialize ⇒ Bar
Returns a new instance of Bar.
6 7 8 |
# File 'lib/bar.rb', line 6 def initialize reset end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
3 4 5 |
# File 'lib/bar.rb', line 3 def current @current end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/bar.rb', line 4 def name @name end |
#total ⇒ Object
Returns the value of attribute total.
4 5 6 |
# File 'lib/bar.rb', line 4 def total @total end |
Instance Method Details
#indicator(current) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bar.rb', line 18 def indicator(current) = Array.new(@bar_size, "_") return .join if current <= 0 prop = current > 0 ? ((100 / (total / current.to_f)) / @bar_step).to_i : 0 return .join if prop <= 0 [0...prop] = Array.new(prop, "#") .join end |
#reset ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/bar.rb', line 10 def reset @name = nil @total = 0 @current = 0 @bar_size = 20 @bar_step = 5 end |
#update(current) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bar.rb', line 29 def update(current) @current = current file = File.basename(@name).ljust(25) STDOUT.print "#{file} : #{self.indicator(current)}\r" if @current >= @total STDOUT.puts "\n" @current = -1 end end |