Class: BootstrapBuilders::ProgressBar

Inherits:
Object
  • Object
show all
Defined in:
lib/bootstrap_builders/progress_bar.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ ProgressBar

Returns a new instance of ProgressBar.



13
14
15
# File 'lib/bootstrap_builders/progress_bar.rb', line 13

def initialize(args)
  @percent = args.fetch(:percent)
end

Class Method Details

.with_parsed_args(*opts) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/bootstrap_builders/progress_bar.rb', line 2

def self.with_parsed_args(*opts)
  percent = opts.shift if opts.first.is_a?(Integer) || opts.first.is_a?(Float) || opts.first.is_a?(Integer)

  args_parser = BootstrapBuilders::ArgumentsParser.new(
    arguments: opts,
    short_true_arguments: []
  )

  BootstrapBuilders::ProgressBar.new({percent: percent}.merge(args_parser.arguments_hash)).html
end

Instance Method Details

#htmlObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bootstrap_builders/progress_bar.rb', line 17

def html
  progress = HtmlGen::Element.new(:div, classes: ["bb-progress-bar", "progress"])

  progress.add_ele(
    :div,
    classes: ["progress-bar"],
    attr: {
      "aria-valuenow" => @percent.to_i,
      "aria-valuemin" => 0,
      "aria-valuemax" => 100,
      role: "progressbar",
      style: "width: #{@percent}%;"
    }
  )

  progress.add_ele(:div, classes: ["bb-progress-bar-label"], str: "#{@percent.to_i}%")
  progress.html
end