class Fontist::Utils::ProgressBar
Public Class Methods
new(total)
click to toggle source
# File lib/fontist/utils/downloader.rb, line 100 def initialize(total) @counter = 0 @total = total @printed_percent = -1 @printed_size = -1 @start = Time.now end
Public Instance Methods
finish()
click to toggle source
# File lib/fontist/utils/downloader.rb, line 118 def finish print Fontist.ui.print(format(", %<mb_per_second>.2f MiB/s, done.\n", mb_per_second: mb_per_second)) end
increment(progress)
click to toggle source
# File lib/fontist/utils/downloader.rb, line 112 def increment(progress) @counter = progress print_incrementally end
total=(total)
click to toggle source
# File lib/fontist/utils/downloader.rb, line 108 def total=(total) @total = total end
Private Instance Methods
byte_to_megabyte()
click to toggle source
# File lib/fontist/utils/downloader.rb, line 175 def byte_to_megabyte @byte_to_megabyte ||= 1024 * 1024 end
counter_mb()
click to toggle source
# File lib/fontist/utils/downloader.rb, line 167 def counter_mb @counter / byte_to_megabyte end
mb_per_second()
click to toggle source
# File lib/fontist/utils/downloader.rb, line 191 def mb_per_second @counter / (Time.now - @start) / byte_to_megabyte end
percent()
click to toggle source
# File lib/fontist/utils/downloader.rb, line 163 def percent (@counter.fdiv(@total) * 100).to_i end
print()
click to toggle source
# File lib/fontist/utils/downloader.rb, line 134 def print if total? print_percent else print_size end end
print_incrementally()
click to toggle source
# File lib/fontist/utils/downloader.rb, line 126 def print_incrementally if total? print_percent_incrementally else print_size_incrementally end end
print_percent()
click to toggle source
# File lib/fontist/utils/downloader.rb, line 154 def print_percent # rubocop:disable Style/FormatStringToken Fontist.ui.print(format("\r\e[0KDownloading: %<completeness>3d%% (%<counter_mb>d/%<total_mb>d MiB)", completeness: percent, counter_mb: counter_mb, total_mb: total_mb)) # rubocop:enable Style/FormatStringToken end
print_percent_incrementally()
click to toggle source
# File lib/fontist/utils/downloader.rb, line 146 def print_percent_incrementally return unless percent > @printed_percent print_percent @printed_percent = percent end
print_size()
click to toggle source
# File lib/fontist/utils/downloader.rb, line 187 def print_size Fontist.ui.print(format("\r\e[0KDownloading: %<downloaded>4d MiB", downloaded: counter_mb)) end
print_size_incrementally()
click to toggle source
# File lib/fontist/utils/downloader.rb, line 179 def print_size_incrementally return unless counter_mb > @printed_size print_size @printed_size = counter_mb end
total?()
click to toggle source
# File lib/fontist/utils/downloader.rb, line 142 def total? !!@total end
total_mb()
click to toggle source
# File lib/fontist/utils/downloader.rb, line 171 def total_mb @total / byte_to_megabyte end