Class: Burner::Library::Collection::Shift

Inherits:
JobWithRegister show all
Defined in:
lib/burner/library/collection/shift.rb

Overview

Take an array and remove the first N elements, where N is specified by the amount attribute. The initial use case for this was to remove “header” rows from arrays, like you would expect when parsing CSV files.

Expected Payload input: nothing. Payload output: An array with N beginning elements removed.

Constant Summary

Constants inherited from JobWithRegister

JobWithRegister::BLANK

Instance Attribute Summary collapse

Attributes inherited from JobWithRegister

#register

Attributes inherited from Job

#name

Instance Method Summary collapse

Methods included from Util::Arrayable

#array

Constructor Details

#initialize(amount: DEFAULT_AMOUNT, name: '', register: DEFAULT_REGISTER) ⇒ Shift

Returns a new instance of Shift.



26
27
28
29
30
31
32
# File 'lib/burner/library/collection/shift.rb', line 26

def initialize(amount: DEFAULT_AMOUNT, name: '', register: DEFAULT_REGISTER)
  super(name: name, register: register)

  @amount = amount.to_i

  freeze
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



24
25
26
# File 'lib/burner/library/collection/shift.rb', line 24

def amount
  @amount
end

Instance Method Details

#perform(output, payload) ⇒ Object



34
35
36
37
38
# File 'lib/burner/library/collection/shift.rb', line 34

def perform(output, payload)
  output.detail("Shifting #{amount} entries.")

  payload[register] = array(payload[register]).slice(amount..-1)
end