mirror of
https://github.com/alphacep/vosk-api.git
synced 2026-03-23 00:01:25 +08:00
* Init gem * WIP * WIP * WIP: Gemify * WIP * Try ffi_gen * Revert "Try ffi_gen" This reverts commit a54e56b35a1bdc079dbe122aff47d79038d4e52f. * Vibecode 1 * Vibecode 2 * rework progressbar * Some ref + test_captcha * Return deleted by Claude * Draft precompiled packaging * Review and refactor C bindings * ref OwnedString * Rename methods and add notes * rubocop * Fix progressbar, add examples * Ref spec * Ref spec - final * Final ver * Add srt, other fixes * Move to ruby dir --------- Co-authored-by: Nickolay V. Shmyrev <nshmyrev@gmail.com>
59 lines
1.8 KiB
Ruby
59 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "progressbar"
|
|
require "bytesize"
|
|
|
|
# Extends progressbar with tqdm-like output:
|
|
# %s / %z → human-readable byte sizes: current size / total siZe
|
|
# %d / %o → compact time: elapsed Duration / Outstanding remaining
|
|
# %r → rate_scale lambda may return a ByteSize string
|
|
|
|
# Override rate_of_change so rate_scale can return a string.
|
|
# The default format '%i' coerces the result to integer, breaking string values.
|
|
ProgressBar::Components::Rate.prepend(Module.new do
|
|
def rate_of_change(format_string = "%s")
|
|
return "0" if elapsed_seconds <= 0
|
|
|
|
format_string % scaled_rate
|
|
end
|
|
end)
|
|
|
|
class ProgressBar # :nodoc: all
|
|
# Add ByteSize-formatted progress methods to the Progress component.
|
|
class Progress
|
|
def progress_with_precision
|
|
ByteSize.new(progress).to_s
|
|
end
|
|
|
|
def total_with_unknown_indicator_with_precision
|
|
total ? ByteSize.new(total).to_s : total_with_unknown_indicator
|
|
end
|
|
end
|
|
|
|
module Components
|
|
# Add label-free time methods to the Time component.
|
|
class Time
|
|
def elapsed_no_label
|
|
val = elapsed
|
|
val.start_with?("00:") ? val[3..-1] : val
|
|
end
|
|
|
|
def estimated_no_label
|
|
val = estimated_with_friendly_oob.split(": ", 2).last
|
|
val.start_with?("00:") ? val[3..-1] : val
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
# Extend MOLECULES with new non-overlapping keys — originals are untouched.
|
|
# remove_const avoids the "already initialized constant" warning.
|
|
molecules = ProgressBar::Format::Molecule::MOLECULES
|
|
ProgressBar::Format::Molecule.send(:remove_const, :MOLECULES)
|
|
ProgressBar::Format::Molecule::MOLECULES = molecules.merge(
|
|
s: %i[progressable progress_with_precision],
|
|
z: %i[progressable total_with_unknown_indicator_with_precision],
|
|
d: %i[time_component elapsed_no_label],
|
|
o: %i[time_component estimated_no_label],
|
|
).freeze
|