Class: ProgressBar::IndexController

Inherits:
Object
  • Object
show all
Defined in:
app/progress-bar/controllers/index_controller.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ IndexController

Returns a new instance of IndexController.



3
4
5
6
7
8
9
10
11
# File 'app/progress-bar/controllers/index_controller.rb', line 3

def initialize(data)
  @data = data
  if !@data.locals.has_key?("value")
    raise "Progress Bar requires a value."
  end
  if !@data.locals.has_key?("total")
    raise "Progress Bar requires a total."
  end
end

Instance Method Details

#classesObject



18
19
20
21
22
23
24
# File 'app/progress-bar/controllers/index_controller.rb', line 18

def classes
  if @data.locals.has_key?("classes")
    @data.classes 
  else
    ""
  end
end

#widthObject



13
14
15
16
# File 'app/progress-bar/controllers/index_controller.rb', line 13

def width
  w = @data.value.to_f / @data.total.to_f * 100
  w.with {|v| [[v, 0].max, 100].min } 
end