Class: OpencBot::NumericIncrementer

Inherits:
BaseIncrementer show all
Defined in:
lib/openc_bot/incrementers/common.rb

Instance Method Summary collapse

Methods inherited from BaseIncrementer

#db_name, #each, #log_progress, new, #position_file_name, #progress_percent, #read_current, #reset_current, #resumable, #resuming_enum, #write_current

Constructor Details

#initialize(name, opts = {}) ⇒ NumericIncrementer

Returns a new instance of NumericIncrementer.



3
4
5
6
7
8
# File 'lib/openc_bot/incrementers/common.rb', line 3

def initialize(name, opts={})
  raise "You must specify an end_val for a NumericIncrementer" if ! opts[:end_val]
  @start_val = opts[:start_val] || 0
  @end_val = opts[:end_val]
  super(name, opts)
end

Instance Method Details

#increment_yielderObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/openc_bot/incrementers/common.rb', line 10

def increment_yielder
  @expected_count = @end_val
  i = @start_val
  loop do
    if i > @end_val
      raise StopIteration
    end
    yield i
    i += 1
  end
end