brew vendor-gems: commit updates.
This commit is contained in:
parent
4d9ea265e5
commit
b9695b2dfe
@ -101,7 +101,7 @@ $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rspec-sorbet-1.9.1/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rspec_junit_formatter-0.6.0/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-ast-1.27.0/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-progressbar-1.11.0/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-progressbar-1.12.0/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/unicode-display_width-2.4.2/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-1.46.0/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-capybara-2.17.1/lib")
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'ruby-progressbar/output'
|
||||
require 'ruby-progressbar/outputs/tty'
|
||||
require 'ruby-progressbar/outputs/non_tty'
|
||||
require 'ruby-progressbar/timer'
|
||||
require 'ruby-progressbar/progress'
|
||||
require 'ruby-progressbar/throttle'
|
||||
require 'ruby-progressbar/calculators/length'
|
||||
require 'ruby-progressbar/calculators/running_average'
|
||||
require 'ruby-progressbar/components'
|
||||
require 'ruby-progressbar/format'
|
||||
require 'ruby-progressbar/base'
|
||||
require 'ruby-progressbar/refinements' if Module.
|
||||
private_instance_methods.
|
||||
include?(:using)
|
||||
|
||||
class ProgressBar
|
||||
def self.create(*args)
|
||||
ProgressBar::Base.new(*args)
|
||||
end
|
||||
end
|
||||
@ -1,9 +0,0 @@
|
||||
class ProgressBar
|
||||
module Calculators
|
||||
class RunningAverage
|
||||
def self.calculate(current_average, new_value_to_average, smoothing_factor)
|
||||
new_value_to_average * (1.0 - smoothing_factor) + current_average * smoothing_factor
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,5 +0,0 @@
|
||||
require 'ruby-progressbar/components/bar'
|
||||
require 'ruby-progressbar/components/percentage'
|
||||
require 'ruby-progressbar/components/rate'
|
||||
require 'ruby-progressbar/components/time'
|
||||
require 'ruby-progressbar/components/title'
|
||||
@ -1,3 +0,0 @@
|
||||
require 'ruby-progressbar/format/molecule'
|
||||
require 'ruby-progressbar/format/formatter'
|
||||
require 'ruby-progressbar/format/string'
|
||||
@ -1,60 +0,0 @@
|
||||
class ProgressBar
|
||||
module Format
|
||||
class Molecule
|
||||
MOLECULES = {
|
||||
:t => [:title_comp, :title],
|
||||
:T => [:title_comp, :title],
|
||||
:c => [:progressable, :progress],
|
||||
:C => [:progressable, :total],
|
||||
:u => [:progressable, :total_with_unknown_indicator],
|
||||
:p => [:percentage, :percentage],
|
||||
:P => [:percentage, :percentage_with_precision],
|
||||
:j => [:percentage, :justified_percentage],
|
||||
:J => [:percentage, :justified_percentage_with_precision],
|
||||
:a => [:time, :elapsed_with_label],
|
||||
:e => [:time, :estimated_with_unknown_oob],
|
||||
:E => [:time, :estimated_with_friendly_oob],
|
||||
:f => [:time, :estimated_with_no_oob],
|
||||
:B => [:bar, :complete_bar],
|
||||
:b => [:bar, :bar],
|
||||
:W => [:bar, :complete_bar_with_percentage],
|
||||
:w => [:bar, :bar_with_percentage],
|
||||
:i => [:bar, :incomplete_space],
|
||||
:r => [:rate, :rate_of_change],
|
||||
:R => [:rate, :rate_of_change_with_precision]
|
||||
}.freeze
|
||||
|
||||
BAR_MOLECULES = %w{W w B b i}.freeze
|
||||
|
||||
attr_accessor :key,
|
||||
:method_name
|
||||
|
||||
def initialize(letter)
|
||||
self.key = letter
|
||||
self.method_name = MOLECULES.fetch(key.to_sym)
|
||||
end
|
||||
|
||||
def bar_molecule?
|
||||
BAR_MOLECULES.include? key
|
||||
end
|
||||
|
||||
def non_bar_molecule?
|
||||
!bar_molecule?
|
||||
end
|
||||
|
||||
def full_key
|
||||
"%#{key}"
|
||||
end
|
||||
|
||||
def lookup_value(environment, length = 0)
|
||||
component = environment.__send__(method_name[0])
|
||||
|
||||
if bar_molecule?
|
||||
component.__send__(method_name[1], length).to_s
|
||||
else
|
||||
component.__send__(method_name[1]).to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,3 +0,0 @@
|
||||
class ProgressBar
|
||||
VERSION = '1.11.0'.freeze
|
||||
end
|
||||
12
Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/ruby-progressbar-1.12.0/lib/ruby-progressbar.rb
vendored
Normal file
12
Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/ruby-progressbar-1.12.0/lib/ruby-progressbar.rb
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'ruby-progressbar/base'
|
||||
require 'ruby-progressbar/refinements' if Module.
|
||||
private_instance_methods.
|
||||
include?(:using)
|
||||
|
||||
class ProgressBar
|
||||
def self.create(*args)
|
||||
ProgressBar::Base.new(*args)
|
||||
end
|
||||
end
|
||||
@ -1,5 +1,17 @@
|
||||
require 'forwardable'
|
||||
|
||||
require 'ruby-progressbar/components/bar'
|
||||
require 'ruby-progressbar/components/percentage'
|
||||
require 'ruby-progressbar/components/rate'
|
||||
require 'ruby-progressbar/components/time'
|
||||
require 'ruby-progressbar/components/title'
|
||||
require 'ruby-progressbar/format/formatter'
|
||||
require 'ruby-progressbar/format/string'
|
||||
require 'ruby-progressbar/outputs/non_tty'
|
||||
require 'ruby-progressbar/outputs/tty'
|
||||
require 'ruby-progressbar/progress'
|
||||
require 'ruby-progressbar/timer'
|
||||
|
||||
class ProgressBar
|
||||
class Base
|
||||
extend Forwardable
|
||||
@ -21,14 +33,14 @@ class Base
|
||||
self.timer = Timer.new(options)
|
||||
self.progressable = Progress.new(options)
|
||||
|
||||
options = options.merge(:timer => timer,
|
||||
:progress => progressable)
|
||||
options = options.merge(:progress => progressable,
|
||||
:timer => timer)
|
||||
|
||||
self.title_comp = Components::Title.new(options)
|
||||
self.bar = Components::Bar.new(options)
|
||||
self.percentage = Components::Percentage.new(options)
|
||||
self.rate = Components::Rate.new(options)
|
||||
self.time = Components::Time.new(options)
|
||||
self.title_component = Components::Title.new(options)
|
||||
self.bar_component = Components::Bar.new(options)
|
||||
self.percentage_component = Components::Percentage.new(options)
|
||||
self.rate_component = Components::Rate.new(options)
|
||||
self.time_component = Components::Time.new(options)
|
||||
|
||||
self.output = Output.detect(options.merge(:bar => self))
|
||||
@format = Format::String.new(output.resolve_format(options[:format]))
|
||||
@ -102,19 +114,19 @@ class Base
|
||||
end
|
||||
|
||||
def progress_mark=(mark)
|
||||
output.refresh_with_format_change { bar.progress_mark = mark }
|
||||
output.refresh_with_format_change { bar_component.progress_mark = mark }
|
||||
end
|
||||
|
||||
def remainder_mark=(mark)
|
||||
output.refresh_with_format_change { bar.remainder_mark = mark }
|
||||
output.refresh_with_format_change { bar_component.remainder_mark = mark }
|
||||
end
|
||||
|
||||
def title
|
||||
title_comp.title
|
||||
title_component.title
|
||||
end
|
||||
|
||||
def title=(title)
|
||||
output.refresh_with_format_change { title_comp.title = title }
|
||||
output.refresh_with_format_change { title_component.title = title }
|
||||
end
|
||||
|
||||
def to_s(new_format = nil)
|
||||
@ -128,17 +140,17 @@ class Base
|
||||
{
|
||||
'output_stream' => output.__send__(:stream),
|
||||
'length' => output.length,
|
||||
'title' => title_comp.title,
|
||||
'progress_mark' => bar.progress_mark,
|
||||
'remainder_mark' => bar.remainder_mark,
|
||||
'title' => title_component.title,
|
||||
'progress_mark' => bar_component.progress_mark,
|
||||
'remainder_mark' => bar_component.remainder_mark,
|
||||
'progress' => progressable.progress,
|
||||
'total' => progressable.total,
|
||||
'percentage' => progressable.percentage_completed_with_precision.to_f,
|
||||
'elapsed_time_in_seconds' => time.__send__(:timer).elapsed_seconds,
|
||||
'estimated_time_remaining_in_seconds' => time.__send__(:estimated_seconds_remaining),
|
||||
'base_rate_of_change' => rate.__send__(:base_rate),
|
||||
'scaled_rate_of_change' => rate.__send__(:scaled_rate),
|
||||
'unknown_progress_animation_steps' => bar.upa_steps,
|
||||
'elapsed_time_in_seconds' => time_component.__send__(:timer).elapsed_seconds,
|
||||
'estimated_time_remaining_in_seconds' => time_component.__send__(:estimated_seconds_remaining),
|
||||
'base_rate_of_change' => rate_component.__send__(:base_rate),
|
||||
'scaled_rate_of_change' => rate_component.__send__(:scaled_rate),
|
||||
'unknown_progress_animation_steps' => bar_component.upa_steps,
|
||||
'throttle_rate' => output.__send__(:throttle).rate,
|
||||
'started?' => started?,
|
||||
'stopped?' => stopped?,
|
||||
@ -164,11 +176,11 @@ class Base
|
||||
attr_accessor :output,
|
||||
:timer,
|
||||
:progressable,
|
||||
:title_comp,
|
||||
:bar,
|
||||
:percentage,
|
||||
:rate,
|
||||
:time,
|
||||
:title_component,
|
||||
:bar_component,
|
||||
:percentage_component,
|
||||
:rate_component,
|
||||
:time_component,
|
||||
:autostart,
|
||||
:autofinish,
|
||||
:finished
|
||||
@ -50,7 +50,6 @@ class Length
|
||||
end
|
||||
# rubocop:enable Style/RescueStandardError
|
||||
|
||||
# rubocop:disable Lint/DuplicateMethods
|
||||
begin
|
||||
require 'io/console'
|
||||
|
||||
@ -68,7 +67,6 @@ class Length
|
||||
dynamic_width_via_system_calls
|
||||
end
|
||||
end
|
||||
# rubocop:enable Lint/DuplicateMethods
|
||||
|
||||
def dynamic_width_via_output_stream_object
|
||||
_rows, columns = output.winsize
|
||||
@ -0,0 +1,9 @@
|
||||
class ProgressBar
|
||||
module Calculators
|
||||
class SmoothedAverage
|
||||
def self.calculate(current_average, new_value_to_average, rate)
|
||||
(new_value_to_average * (1.0 - rate)) + (current_average * rate)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -32,22 +32,6 @@ class Bar
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def integrated_percentage_complete_string
|
||||
return standard_complete_string if completed_length < 5
|
||||
|
||||
" #{progress.percentage_completed} ".to_s.center(completed_length, progress_mark)
|
||||
end
|
||||
|
||||
def standard_complete_string
|
||||
progress_mark * completed_length
|
||||
end
|
||||
|
||||
def incomplete_string
|
||||
remainder_mark * (length - completed_length)
|
||||
end
|
||||
|
||||
def bar(length)
|
||||
self.length = length
|
||||
|
||||
@ -66,12 +50,6 @@ class Bar
|
||||
to_s(:format => :integrated_percentage)
|
||||
end
|
||||
|
||||
def unknown_string
|
||||
unknown_frame_string = unknown_progress_frame * ((length / upa_steps.size) + 2)
|
||||
|
||||
unknown_frame_string[0, length]
|
||||
end
|
||||
|
||||
def incomplete_space(length)
|
||||
self.length = length
|
||||
|
||||
@ -88,6 +66,28 @@ class Bar
|
||||
integrated_percentage_complete_string
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def integrated_percentage_complete_string
|
||||
return standard_complete_string if completed_length < 5
|
||||
|
||||
" #{progress.percentage_completed} ".to_s.center(completed_length, progress_mark)
|
||||
end
|
||||
|
||||
def standard_complete_string
|
||||
progress_mark * completed_length
|
||||
end
|
||||
|
||||
def incomplete_string
|
||||
remainder_mark * (length - completed_length)
|
||||
end
|
||||
|
||||
def unknown_string
|
||||
unknown_frame_string = unknown_progress_frame * ((length / upa_steps.size) + 2)
|
||||
|
||||
unknown_frame_string[0, length]
|
||||
end
|
||||
|
||||
def completed_length
|
||||
(length * progress.percentage_completed / 100).floor
|
||||
end
|
||||
@ -7,10 +7,8 @@ class Percentage
|
||||
self.progress = options[:progress]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def percentage
|
||||
progress.percentage_completed
|
||||
progress.percentage_completed.to_s
|
||||
end
|
||||
|
||||
def justified_percentage
|
||||
@ -2,23 +2,17 @@ class ProgressBar
|
||||
module Components
|
||||
class Rate
|
||||
attr_accessor :rate_scale,
|
||||
:started_at,
|
||||
:stopped_at,
|
||||
:timer,
|
||||
:progress
|
||||
|
||||
def initialize(options = {})
|
||||
self.rate_scale = options[:rate_scale] || lambda { |x| x }
|
||||
self.started_at = nil
|
||||
self.stopped_at = nil
|
||||
self.timer = options[:timer]
|
||||
self.progress = options[:progress]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rate_of_change(format_string = '%i')
|
||||
return 0 unless elapsed_seconds > 0
|
||||
return '0' if elapsed_seconds <= 0
|
||||
|
||||
format_string % scaled_rate
|
||||
end
|
||||
@ -27,6 +21,8 @@ class Rate
|
||||
rate_of_change('%.2f')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def scaled_rate
|
||||
rate_scale.call(base_rate)
|
||||
end
|
||||
@ -12,60 +12,56 @@ class Time
|
||||
NO_TIME_ELAPSED_TEXT = '--:--:--'.freeze
|
||||
ESTIMATED_LABEL = ' ETA'.freeze
|
||||
ELAPSED_LABEL = 'Time'.freeze
|
||||
WALL_CLOCK_FORMAT = '%H:%M:%S'.freeze
|
||||
OOB_TEXT_TO_FORMAT = {
|
||||
:unknown => OOB_UNKNOWN_TIME_TEXT,
|
||||
:friendly => OOB_FRIENDLY_TIME_TEXT
|
||||
}.freeze
|
||||
|
||||
def initialize(options = {})
|
||||
self.out_of_bounds_time_format = options[:out_of_bounds_time_format]
|
||||
self.timer = options[:timer]
|
||||
self.progress = options[:progress]
|
||||
self.timer = options[:timer]
|
||||
self.progress = options[:progress]
|
||||
end
|
||||
|
||||
def estimated_with_label
|
||||
"#{ESTIMATED_LABEL}: #{estimated}"
|
||||
def estimated_with_label(out_of_bounds_time_format = nil)
|
||||
"#{ESTIMATED_LABEL}: #{estimated(out_of_bounds_time_format)}"
|
||||
end
|
||||
|
||||
def elapsed_with_label
|
||||
"#{ELAPSED_LABEL}: #{elapsed}"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def estimated_with_no_oob
|
||||
self.out_of_bounds_time_format = nil
|
||||
|
||||
estimated_with_elapsed_fallback
|
||||
estimated_with_elapsed_fallback(nil)
|
||||
end
|
||||
|
||||
def estimated_with_unknown_oob
|
||||
self.out_of_bounds_time_format = :unknown
|
||||
|
||||
estimated_with_elapsed_fallback
|
||||
estimated_with_elapsed_fallback(:unknown)
|
||||
end
|
||||
|
||||
def estimated_with_friendly_oob
|
||||
self.out_of_bounds_time_format = :friendly
|
||||
|
||||
estimated_with_elapsed_fallback
|
||||
estimated_with_elapsed_fallback(:friendly)
|
||||
end
|
||||
|
||||
attr_reader :out_of_bounds_time_format
|
||||
def estimated_wall_clock
|
||||
return timer.stopped_at.strftime(WALL_CLOCK_FORMAT) if progress.finished?
|
||||
return NO_TIME_ELAPSED_TEXT unless timer.started?
|
||||
|
||||
memo_estimated_seconds_remaining = estimated_seconds_remaining
|
||||
return NO_TIME_ELAPSED_TEXT unless memo_estimated_seconds_remaining
|
||||
|
||||
(timer.now + memo_estimated_seconds_remaining).
|
||||
strftime(WALL_CLOCK_FORMAT)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
attr_accessor :timer,
|
||||
:progress
|
||||
|
||||
def out_of_bounds_time_format=(format)
|
||||
unless OOB_TIME_FORMATS.include? format
|
||||
fail StandardError, "Invalid Out Of Bounds time format. Valid formats are #{OOB_TIME_FORMATS.inspect}"
|
||||
end
|
||||
|
||||
@out_of_bounds_time_format = format
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def estimated
|
||||
def estimated(out_of_bounds_time_format)
|
||||
memo_estimated_seconds_remaining = estimated_seconds_remaining
|
||||
|
||||
return OOB_UNKNOWN_TIME_TEXT unless memo_estimated_seconds_remaining
|
||||
@ -73,7 +69,7 @@ class Time
|
||||
hours, minutes, seconds = timer.divide_seconds(memo_estimated_seconds_remaining)
|
||||
|
||||
if hours > OOB_LIMIT_IN_HOURS && out_of_bounds_time_format
|
||||
OOB_TEXT_TO_FORMAT[out_of_bounds_time_format]
|
||||
OOB_TEXT_TO_FORMAT.fetch(out_of_bounds_time_format)
|
||||
else
|
||||
TIME_FORMAT % [hours, minutes, seconds]
|
||||
end
|
||||
@ -87,14 +83,16 @@ class Time
|
||||
TIME_FORMAT % [hours, minutes, seconds]
|
||||
end
|
||||
|
||||
def estimated_with_elapsed_fallback
|
||||
progress.finished? ? elapsed_with_label : estimated_with_label
|
||||
def estimated_with_elapsed_fallback(out_of_bounds_time_format)
|
||||
return elapsed_with_label if progress.finished?
|
||||
|
||||
estimated_with_label(out_of_bounds_time_format)
|
||||
end
|
||||
|
||||
def estimated_seconds_remaining
|
||||
return if progress.unknown? || progress.none? || timer.stopped? || timer.reset?
|
||||
|
||||
(timer.elapsed_seconds * (progress.total / progress.running_average - 1)).round
|
||||
(timer.elapsed_seconds * ((progress.total / progress.running_average) - 1)).round
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -13,7 +13,7 @@ class Formatter
|
||||
bar_length = max_length -
|
||||
processed_string.displayable_length +
|
||||
format_string.bar_molecule_placeholder_length
|
||||
bar_length = (bar_length < 0) ? 0 : bar_length
|
||||
bar_length = 0 if bar_length < 0
|
||||
|
||||
format_string.bar_molecules.each do |molecule|
|
||||
processed_string.gsub!(molecule.full_key,
|
||||
@ -0,0 +1,61 @@
|
||||
class ProgressBar
|
||||
module Format
|
||||
class Molecule
|
||||
MOLECULES = {
|
||||
:t => [:title_component, :title],
|
||||
:T => [:title_component, :title],
|
||||
:c => [:progressable, :progress],
|
||||
:C => [:progressable, :total],
|
||||
:u => [:progressable, :total_with_unknown_indicator],
|
||||
:p => [:percentage_component, :percentage],
|
||||
:P => [:percentage_component, :percentage_with_precision],
|
||||
:j => [:percentage_component, :justified_percentage],
|
||||
:J => [:percentage_component, :justified_percentage_with_precision],
|
||||
:a => [:time_component, :elapsed_with_label],
|
||||
:e => [:time_component, :estimated_with_unknown_oob],
|
||||
:E => [:time_component, :estimated_with_friendly_oob],
|
||||
:f => [:time_component, :estimated_with_no_oob],
|
||||
:l => [:time_component, :estimated_wall_clock],
|
||||
:B => [:bar_component, :complete_bar],
|
||||
:b => [:bar_component, :bar],
|
||||
:W => [:bar_component, :complete_bar_with_percentage],
|
||||
:w => [:bar_component, :bar_with_percentage],
|
||||
:i => [:bar_component, :incomplete_space],
|
||||
:r => [:rate_component, :rate_of_change],
|
||||
:R => [:rate_component, :rate_of_change_with_precision]
|
||||
}.freeze
|
||||
|
||||
BAR_MOLECULES = %w{W w B b i}.freeze
|
||||
|
||||
attr_accessor :key,
|
||||
:method_name
|
||||
|
||||
def initialize(letter)
|
||||
self.key = letter
|
||||
self.method_name = MOLECULES.fetch(key.to_sym)
|
||||
end
|
||||
|
||||
def bar_molecule?
|
||||
BAR_MOLECULES.include? key
|
||||
end
|
||||
|
||||
def non_bar_molecule?
|
||||
!bar_molecule?
|
||||
end
|
||||
|
||||
def full_key
|
||||
"%#{key}"
|
||||
end
|
||||
|
||||
def lookup_value(environment, length = 0)
|
||||
component = environment.__send__(method_name[0])
|
||||
|
||||
if bar_molecule?
|
||||
component.__send__(method_name[1], length).to_s
|
||||
else
|
||||
component.__send__(method_name[1]).to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,3 +1,5 @@
|
||||
require 'ruby-progressbar/format/molecule'
|
||||
|
||||
class ProgressBar
|
||||
module Format
|
||||
class String < ::String
|
||||
@ -1,3 +1,6 @@
|
||||
require 'ruby-progressbar/calculators/length'
|
||||
require 'ruby-progressbar/throttle'
|
||||
|
||||
class ProgressBar
|
||||
class Output
|
||||
DEFAULT_OUTPUT_STREAM = $stdout
|
||||
@ -1,21 +1,33 @@
|
||||
require 'ruby-progressbar/errors/invalid_progress_error'
|
||||
require 'ruby-progressbar/calculators/smoothed_average'
|
||||
|
||||
class ProgressBar
|
||||
class Progress
|
||||
DEFAULT_TOTAL = 100
|
||||
DEFAULT_BEGINNING_POSITION = 0
|
||||
DEFAULT_SMOOTHING = 0.1
|
||||
DEFAULT_TOTAL = 100
|
||||
DEFAULT_BEGINNING_POSITION = 0
|
||||
DEFAULT_RUNNING_AVERAGE_RATE = 0.1
|
||||
DEFAULT_RUNNING_AVERAGE_CALCULATOR = ProgressBar::Calculators::SmoothedAverage
|
||||
|
||||
RUNNING_AVERAGE_CALCULATOR_MAP = {
|
||||
'smoothing' => ProgressBar::Calculators::SmoothedAverage
|
||||
}.freeze
|
||||
|
||||
attr_reader :total,
|
||||
:progress
|
||||
|
||||
attr_accessor :starting_position,
|
||||
:running_average,
|
||||
:smoothing
|
||||
:running_average_calculator,
|
||||
:running_average_rate
|
||||
|
||||
def initialize(options = {})
|
||||
self.total = options.fetch(:total, DEFAULT_TOTAL)
|
||||
self.smoothing = options[:smoothing] || DEFAULT_SMOOTHING
|
||||
self.total = options.fetch(:total, DEFAULT_TOTAL)
|
||||
self.running_average_rate = options[:smoothing] ||
|
||||
options[:running_average_rate] ||
|
||||
DEFAULT_RUNNING_AVERAGE_RATE
|
||||
self.running_average_calculator = RUNNING_AVERAGE_CALCULATOR_MAP.
|
||||
fetch(options[:running_average_calculator],
|
||||
DEFAULT_RUNNING_AVERAGE_CALCULATOR)
|
||||
|
||||
start :at => DEFAULT_BEGINNING_POSITION
|
||||
end
|
||||
@ -66,9 +78,9 @@ class Progress
|
||||
|
||||
@progress = new_progress
|
||||
|
||||
self.running_average = Calculators::RunningAverage.calculate(running_average,
|
||||
absolute,
|
||||
smoothing)
|
||||
self.running_average = running_average_calculator.calculate(running_average,
|
||||
absolute,
|
||||
running_average_rate)
|
||||
end
|
||||
|
||||
def total=(new_total)
|
||||
@ -17,11 +17,9 @@ class Time
|
||||
end
|
||||
|
||||
def unmocked_time_method
|
||||
@unmocked_time_method ||= begin
|
||||
TIME_MOCKING_LIBRARY_METHODS.find do |method|
|
||||
time.respond_to? method
|
||||
end
|
||||
end
|
||||
@unmocked_time_method ||= TIME_MOCKING_LIBRARY_METHODS.find do |method|
|
||||
time.respond_to? method
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
@ -28,6 +28,10 @@ class Timer
|
||||
start
|
||||
end
|
||||
|
||||
def now
|
||||
time.now
|
||||
end
|
||||
|
||||
def started?
|
||||
started_at
|
||||
end
|
||||
@ -51,6 +55,8 @@ class Timer
|
||||
end
|
||||
|
||||
def elapsed_seconds
|
||||
return 0 unless started?
|
||||
|
||||
((stopped_at || time.now) - started_at)
|
||||
end
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
class ProgressBar
|
||||
VERSION = '1.12.0'.freeze
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user