Module: BootstrapProgressbar::Helper::Private

Included in:
BootstrapProgressbar::Helper
Defined in:
lib/bootstrap_progressbar/helper.rb

Class Method Summary collapse

Class Method Details

.check_percent(percent) ⇒ Object



5
6
7
8
9
# File 'lib/bootstrap_progressbar/helper.rb', line 5

def self.check_percent(percent)
  if percent < 0 || percent > 1
    throw ArgumentError.new('the percent(first argument) should between 0 to 1')
  end
end

.only_progress_bar(percent, options = {}) ⇒ Object

generate a bootstrap progress-bar with a percent and custom options Params:

percent

Fixnum between 0 to 1.00

options

alternative: [‘success’, ‘danger’, ‘warning’, ‘info’] striped: boolean active: boolean label: boolean class: a string contained more given class



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bootstrap_progressbar/helper.rb', line 20

def self.only_progress_bar(percent, options = {})
  percent *= 100
  percent = percent.to_i

  case options[:alternative]
    when 'success'
    alternative = 'progress-bar-success'
    when 'danger'
    alternative = 'progress-bar-danger'
    when 'warning'
    alternative = 'progress-bar-warning'
    when 'info'
    alternative = 'progress-bar-info'
    else
    alternative = ''
  end

  if options[:active]
    striped = "progress-bar-striped active"
  elsif options[:striped]
    striped = "progress-bar-striped"
  else
    striped = ""
  end

  clazz = options[:class] if options[:class]

  unless options[:label]
    percent_and_label = "<span class='sr-only'>#{percent}%</span>"
  else
    percent_and_label = "#{percent}%"
  end

  "<div class='#{[clazz, 'progress-bar', alternative, striped].join(' ').strip()}' role='progressbar' aria-valuenow='#{percent}' aria-valuemin='0' aria-valuemax='100' style='width: #{percent}%'>#{percent_and_label}</div>"
end