class Realize::Collection::AtIndex
Transformer to get an item of a collection
Attributes
index[R]
Public Class Methods
new(index:)
click to toggle source
# File lib/realize/collection/at_index.rb, line 18 def initialize(index:) raise ArgumentError, 'index is required' if index.to_s.empty? @index = index.to_i freeze end
Public Instance Methods
transform(_resolver, value, _time, _record)
click to toggle source
# File lib/realize/collection/at_index.rb, line 26 def transform(_resolver, value, _time, _record) value.is_a?(Array) ? value[index] : value end