Class: Ui::Progress::Component

Inherits:
BaseComponent
  • Object
show all
Defined in:
lib/uikit_rails/templates/components/progress/component.rb

Overview

Progress bar showing completion percentage.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value: 0, max: 100, **html_attrs) ⇒ Component

Returns a new instance of Component.



9
10
11
12
13
14
# File 'lib/uikit_rails/templates/components/progress/component.rb', line 9

def initialize(value: 0, max: 100, **html_attrs)
  @value = value.to_i
  @max = max.to_i
  @html_attrs = html_attrs
  super()
end

Instance Attribute Details

#html_attrsObject (readonly)

Returns the value of attribute html_attrs.



7
8
9
# File 'lib/uikit_rails/templates/components/progress/component.rb', line 7

def html_attrs
  @html_attrs
end

#maxObject (readonly)

Returns the value of attribute max.



7
8
9
# File 'lib/uikit_rails/templates/components/progress/component.rb', line 7

def max
  @max
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/uikit_rails/templates/components/progress/component.rb', line 7

def value
  @value
end

Instance Method Details

#percentageObject



16
17
18
19
20
# File 'lib/uikit_rails/templates/components/progress/component.rb', line 16

def percentage
  return 0 if max.zero?

  [(value.to_f / max * 100).round, 100].min
end