Module: Progress::InstanceMethods

Included in:
Progress
Defined in:
lib/progress.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#currentObject

Returns the value of attribute current.



7
8
9
# File 'lib/progress.rb', line 7

def current
  @current
end

#current_stepObject (readonly)

Returns the value of attribute current_step.



8
9
10
# File 'lib/progress.rb', line 8

def current_step
  @current_step
end

#noteObject

Returns the value of attribute note.



7
8
9
# File 'lib/progress.rb', line 7

def note
  @note
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/progress.rb', line 7

def title
  @title
end

#totalObject

Returns the value of attribute total.



7
8
9
# File 'lib/progress.rb', line 7

def total
  @total
end

Instance Method Details

#initialize(title, total) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/progress.rb', line 9

def initialize(title, total)
  if title.is_a?(Numeric) && total.nil?
    title, total = nil, title
  elsif total.nil?
    total = 1
  end
  @title = title
  @current = 0.0
  @total = total == 0.0 ? 1.0 : Float(total)
end

#step(steps) ⇒ Object



34
35
36
37
38
39
# File 'lib/progress.rb', line 34

def step(steps)
  @current_step = steps
  yield
ensure
  @current_step = nil
end

#step_if_blankObject



20
21
22
23
24
# File 'lib/progress.rb', line 20

def step_if_blank
  if current == 0.0 && total == 1.0
    self.current = 1.0
  end
end

#to_f(inner) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/progress.rb', line 26

def to_f(inner)
  inner = [inner, 1.0].min
  if current_step
    inner *= current_step
  end
  (current + inner) / total
end