Sha256: a8bdbe8f4fded4a7bba8c785f6ee69a5a34218fb7c410fa2b605d242ddd7d154

Contents?: true

Size: 953 Bytes

Versions: 7

Compression:

Stored size: 953 Bytes

Contents

class BootstrapBuilders::ProgressBar
  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

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

  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
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bootstrap_builders-1.0.4 lib/bootstrap_builders/progress_bar.rb
bootstrap_builders-0.0.63 lib/bootstrap_builders/progress_bar.rb
bootstrap_builders-1.0.3 lib/bootstrap_builders/progress_bar.rb
bootstrap_builders-1.0.2 lib/bootstrap_builders/progress_bar.rb
bootstrap_builders-1.0.1 lib/bootstrap_builders/progress_bar.rb
bootstrap_builders-1.0.0 lib/bootstrap_builders/progress_bar.rb
bootstrap_builders-0.0.62 lib/bootstrap_builders/progress_bar.rb