Module: Rolemodel::Utility::TaskTools
- Defined in:
- lib/rolemodel/utility/task_tools.rb
Constant Summary collapse
- PROGRESS =
%w[⠏ ⠇ ⠧ ⠦ ⠴ ⠼ ⠸ ⠹ ⠙ ⠋].cycle
Instance Method Summary collapse
-
#indicate_progress(index, total = nil, report_interval: 9) ⇒ Object
Indicate the progress of a long-running process.
- #say(message, subitem: false) ⇒ Object
-
#say_with_time(message) ⇒ Object
based on the migration helper of the same name.
Instance Method Details
#indicate_progress(index, total = nil, report_interval: 9) ⇒ Object
Indicate the progress of a long-running process
Usage (with a known total): 100.times do |i| indicate_progress(i, 100) end
Only update every 'report_interval' iteration for eye-trackable animation speed Also displays a completion percentage if a total is provided
29 30 31 32 33 |
# File 'lib/rolemodel/utility/task_tools.rb', line 29 def indicate_progress(index, total = nil, report_interval: 9) return unless (index % report_interval).zero? print("#{PROGRESS.next} #{to_percent(index, total) if total}\r") # rubocop:disable Rails/Output end |
#say(message, subitem: false) ⇒ Object
15 16 17 |
# File 'lib/rolemodel/utility/task_tools.rb', line 15 def say(, subitem: false) puts "#{subitem ? ' ->' : '--'} #{}" # rubocop:disable Rails/Output end |
#say_with_time(message) ⇒ Object
based on the migration helper of the same name
9 10 11 12 13 |
# File 'lib/rolemodel/utility/task_tools.rb', line 9 def say_with_time(, &) say time = Benchmark.measure(&) say '%.4fs' % time.real, subitem: true end |