class Realize::Collection::Join

Transformer to return a new string by concatenating all the elements of an array specified by a separator character. The transformer also can be configured to specifiy which elements to start from and end to that will make up the returned string.

Constants

DEFAULT_END_INDEX
DEFAULT_SEPARATOR
DEFAULT_START_INDEX

Attributes

end_index[R]
separator[R]
start_index[R]

Public Class Methods

new(separator: DEFAULT_SEPARATOR, start_index: DEFAULT_START_INDEX, end_index: DEFAULT_END_INDEX) click to toggle source
# File lib/realize/collection/join.rb, line 25
def initialize(separator: DEFAULT_SEPARATOR, start_index: DEFAULT_START_INDEX,
               end_index: DEFAULT_END_INDEX)
  @separator    = separator || DEFAULT_SEPARATOR
  @start_index  = start_index || DEFAULT_START_INDEX
  @end_index    = end_index || DEFAULT_END_INDEX

  freeze
end

Public Instance Methods

transform(_resolver, value, _time, _record) click to toggle source
# File lib/realize/collection/join.rb, line 34
def transform(_resolver, value, _time, _record)
  items = array(value)

  (items[start_index..end_index] || []).join(separator)
end