Class: Burner::Library::Collection::Shift
- Inherits:
-
JobWithRegister
- Object
- Job
- JobWithRegister
- Burner::Library::Collection::Shift
- 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
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
Attributes inherited from JobWithRegister
Attributes inherited from Job
Instance Method Summary collapse
-
#initialize(amount: DEFAULT_AMOUNT, name: '', register: DEFAULT_REGISTER) ⇒ Shift
constructor
A new instance of Shift.
- #perform(output, payload) ⇒ Object
Methods included from Util::Arrayable
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
#amount ⇒ Object (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 |