Class: Echo::ProgressBar

Inherits:
Object
  • Object
show all
Defined in:
lib/rake-echo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(total) ⇒ ProgressBar

Returns a new instance of ProgressBar.



8
9
10
11
12
13
# File 'lib/rake-echo.rb', line 8

def initialize(total)
  @total = total
  @current = 0
  @start_time = Time.now
  @previous_time = @start_time
end

Instance Attribute Details

#currentObject (readonly)

Returns the value of attribute current.



5
6
7
# File 'lib/rake-echo.rb', line 5

def current
  @current
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



6
7
8
# File 'lib/rake-echo.rb', line 6

def start_time
  @start_time
end

#totalObject (readonly)

Returns the value of attribute total.



4
5
6
# File 'lib/rake-echo.rb', line 4

def total
  @total
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/rake-echo.rb', line 26

def completed?
  @current == @total
end

#increment(amount = 1) ⇒ Object



15
16
17
18
19
20
# File 'lib/rake-echo.rb', line 15

def increment(amount=1)
  @current += amount
  display

  finish if completed?
end

#percentageObject



22
23
24
# File 'lib/rake-echo.rb', line 22

def percentage
  current.to_f / total.to_f
end