Class: Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/completion-progress/engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Engine

Returns a new instance of Engine.



7
8
9
10
11
12
13
14
# File 'lib/completion-progress/engine.rb', line 7

def initialize(options = {})
  @value = 0
  @total_value = 0
  @percent = 0
  @hints = Hash.new
  @steps = Hash.new
  @auto_update = options.has_key?(:auto_update) ? options[:auto_update] : true
end

Instance Attribute Details

#auto_updateObject (readonly)

Returns the value of attribute auto_update.



4
5
6
# File 'lib/completion-progress/engine.rb', line 4

def auto_update
  @auto_update
end

#hintsObject (readonly)

Returns the value of attribute hints.



4
5
6
# File 'lib/completion-progress/engine.rb', line 4

def hints
  @hints
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/completion-progress/engine.rb', line 5

def parent
  @parent
end

#percentObject (readonly)

Returns the value of attribute percent.



4
5
6
# File 'lib/completion-progress/engine.rb', line 4

def percent
  @percent
end

#stepsObject (readonly)

Returns the value of attribute steps.



4
5
6
# File 'lib/completion-progress/engine.rb', line 4

def steps
  @steps
end

#total_valueObject (readonly)

Returns the value of attribute total_value.



4
5
6
# File 'lib/completion-progress/engine.rb', line 4

def total_value
  @total_value
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/completion-progress/engine.rb', line 4

def value
  @value
end

Instance Method Details

#step(name, value, options = {}, &block) ⇒ Object



16
17
18
19
20
21
# File 'lib/completion-progress/engine.rb', line 16

def step(name, value, options = {}, &block)
  if !@steps.has_key?(name)
    @steps[name] = Step.new(name, value, options, &block)
    @total_value += value
  end
end

#updateObject



23
24
25
26
27
28
29
30
# File 'lib/completion-progress/engine.rb', line 23

def update
  @value = 0
  @hints = Hash.new
  @steps.each do |key, step|
    step.process(parent) ? @value += step.value : @hints[step.name] = step.hint
  end
  @percent = @value * 100 / @total_value
end