Class: Engine
- Inherits:
-
Object
- Object
- Engine
- Defined in:
- lib/completion-progress/engine.rb
Instance Attribute Summary collapse
-
#auto_update ⇒ Object
readonly
Returns the value of attribute auto_update.
-
#hints ⇒ Object
readonly
Returns the value of attribute hints.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#percent ⇒ Object
readonly
Returns the value of attribute percent.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#total_value ⇒ Object
readonly
Returns the value of attribute total_value.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Engine
constructor
A new instance of Engine.
- #step(name, value, options = {}, &block) ⇒ Object
- #update ⇒ Object
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( = {}) @value = 0 @total_value = 0 @percent = 0 @hints = Hash.new @steps = Hash.new @auto_update = .has_key?(:auto_update) ? [:auto_update] : true end |
Instance Attribute Details
#auto_update ⇒ Object (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 |
#hints ⇒ Object (readonly)
Returns the value of attribute hints.
4 5 6 |
# File 'lib/completion-progress/engine.rb', line 4 def hints @hints end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/completion-progress/engine.rb', line 5 def parent @parent end |
#percent ⇒ Object (readonly)
Returns the value of attribute percent.
4 5 6 |
# File 'lib/completion-progress/engine.rb', line 4 def percent @percent end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
4 5 6 |
# File 'lib/completion-progress/engine.rb', line 4 def steps @steps end |
#total_value ⇒ Object (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 |
#value ⇒ Object (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, = {}, &block) if !@steps.has_key?(name) @steps[name] = Step.new(name, value, , &block) @total_value += value end end |
#update ⇒ Object
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 |