class Burner::Library::Collection::Number

This job can iterate over a set of records and sequence them (set the specified key to a sequential index value.)

Expected Payload input: array of objects. Payload output: array of objects.

Constants

BLANK
DEFAULT_KEY
DEFAULT_START_AT

Attributes

key[R]
resolver[R]
start_at[R]

Public Class Methods

new( key: DEFAULT_KEY, name: BLANK, register: Burner::DEFAULT_REGISTER, separator: BLANK, start_at: DEFAULT_START_AT ) click to toggle source
Calls superclass method Burner::JobWithRegister::new
# File lib/burner/library/collection/number.rb, line 25
def initialize(
  key: DEFAULT_KEY,
  name: BLANK,
  register: Burner::DEFAULT_REGISTER,
  separator: BLANK,
  start_at: DEFAULT_START_AT
)
  super(name: name, register: register)

  @key      = key.to_s
  @resolver = Objectable.resolver(separator: separator)
  @start_at = start_at.to_i

  freeze
end

Public Instance Methods

perform(output, payload) click to toggle source
# File lib/burner/library/collection/number.rb, line 41
def perform(output, payload)
  output.detail("Setting '#{key}' for each record with values starting at #{start_at}")

  ensure_array(payload).each.with_index(start_at) do |record, index|
    resolver.set(record, key, index)
  end
end