diff --git a/app/models/study_downloader.rb b/app/models/study_downloader.rb index 03138d48..34b23347 100644 --- a/app/models/study_downloader.rb +++ b/app/models/study_downloader.rb @@ -76,6 +76,20 @@ def self.find_studies_to_remove end + private + + def self.print_progress(current, total, message_prefix="downloading") + progress = (current.to_f / total * 100).round(2) + formatted_progress = '%.2f' % progress # Ensures two decimal places + # extra spaces to ensure that the previous print is overwritten + if current == total + puts "\r#{message_prefix} #{total} studies: 100% " + else + print "\r#{message_prefix} #{total} studies: #{formatted_progress}% " + end + end + + private def self.print_progress(current, total, message_prefix="downloading")