Class: Flex::ProgBar

Inherits:
Object
  • Object
show all
Defined in:
lib/flex/prog_bar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, prefix_message=nil)
  @total_count      = total_count
  @successful_count = 0
  @failed_count     = 0
  @pbar             = ::ProgressBar.new('processing...', total_count)
  @pbar.clear
  @pbar.bar_mark = '|'
  puts '_' * @pbar.send(:get_term_width)
  message = "#{prefix_message}Processing #{total_count} documents"
  message << " in batches of #{batch_size}:" unless batch_size.nil?
  puts message
  @pbar.send(:show)
end

Instance Attribute Details

#pbarObject (readonly)

Returns the value of attribute pbar.



4
5
6
# File 'lib/flex/prog_bar.rb', line 4

def pbar
  @pbar
end

#total_countObject (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

#finishObject



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.bar_mark = 'F'
    end
    @failed_count     += result.failed.size
    @successful_count += result.successful.size
  end
  @pbar.inc(inc)
end