Method: Megatron::ProgressHelper#capacity_bar

Defined in:
app/helpers/megatron/progress_helper.rb

#capacity_bar(size, total = 100, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/megatron/progress_helper.rb', line 35

def capacity_bar(size, total=100, options={})
  # make total an optional argument
  if total.is_a?(Hash)
    options = total
    total = 100
  end

  percentage = ((size.to_f / total.to_f) * 100).round

  if percentage > 90
    options[:color] = 'red'
  elsif percentage > 80
    options[:color] = 'orange'
  end

  unless options.delete(:label) == false
    options[:label] = "#{percentage}% - #{number_to_human_size(size).sub(' ','')} / #{number_to_human_size(total).sub(' ','')}"
  end

  progress_bar(percentage, options)
end