Class: Flex::ProgBar
- Inherits:
-
Object
- Object
- Flex::ProgBar
- Defined in:
- lib/flex/prog_bar.rb
Instance Attribute Summary collapse
-
#pbar ⇒ Object
readonly
Returns the value of attribute pbar.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(total_count, batch_size = nil, prefix_message = nil) ⇒ ProgBar
constructor
A new instance of ProgBar.
- #process_result(result, inc) ⇒ Object
Constructor Details
#initialize(total_count, batch_size = nil, prefix_message = nil) ⇒ ProgBar
Returns a new instance of ProgBar.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/flex/prog_bar.rb', line 6 def initialize(total_count, batch_size=nil, =nil) @total_count = total_count @successful_count = 0 @failed_count = 0 @pbar = ::ProgressBar.new('processing...', total_count) @pbar.clear @pbar. = '|' puts '_' * @pbar.send(:get_term_width) = "#{}Processing #{total_count} documents" << " in batches of #{batch_size}:" unless batch_size.nil? puts @pbar.send(:show) end |
Instance Attribute Details
#pbar ⇒ Object (readonly)
Returns the value of attribute pbar.
4 5 6 |
# File 'lib/flex/prog_bar.rb', line 4 def @pbar end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
4 5 6 |
# File 'lib/flex/prog_bar.rb', line 4 def total_count @total_count end |
Instance Method Details
#finish ⇒ Object
32 33 34 35 36 |
# File 'lib/flex/prog_bar.rb', line 32 def finish @pbar.finish puts "Processed #@total_count. Successful #@successful_count. Skipped #{@total_count - @successful_count - @failed_count}. Failed #@failed_count." puts 'See the log for the details about the failures.' unless @failed_count == 0 end |
#process_result(result, inc) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/flex/prog_bar.rb', line 20 def process_result(result, inc) unless result.nil? || result.empty? unless result.failed.size == 0 Conf.logger.error "Failed load:\n#{result.failed.to_yaml}" @pbar. = 'F' end @failed_count += result.failed.size @successful_count += result.successful.size end @pbar.inc(inc) end |