Class: Flammarion::Writeable::Progress

Inherits:
Object
  • Object
show all
Defined in:
lib/cem/cflame/progress.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, owner) ⇒ Progress

Returns a new instance of Progress.



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

def initialize(name, owner)
  @name = name
  @owner = owner
  @owner.raw("<div id='progressBar' style='width: 100%; height: 22px; border: 1px solid #8f8f8f; background-color: #292929; border-radius: 2px; box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25) inset;'><div id='progressBarInner-#{@name}' style='height: 100%; color: #fff; text-align: center; line-height: 22px; width: 0px; background-color: #0099ff;'></div></div>")
end

Instance Method Details

#each(ary, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cem/cflame/progress.rb', line 26

def each(ary, &block)
  set(0)
  @max = ary.size
  return if @max == 0
  
  ary.each_with_index { |a, i|
    yield a
    set(i * 100 / @max)
  }
  ary        
end

#set(value) ⇒ Object



38
39
40
41
# File 'lib/cem/cflame/progress.rb', line 38

def set(value)
  value = value.to_s
  @owner.js("$( '#progressBarInner-#{@name}' ).width('#{value}%').html('#{value}%');")
end