Class: Realize::Collection::Join
- Inherits:
-
Object
- Object
- Realize::Collection::Join
- Includes:
- Arrays
- Defined in:
- lib/realize/collection/join.rb
Overview
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.
Constant Summary collapse
- DEFAULT_END_INDEX =
-1
- DEFAULT_SEPARATOR =
''
- DEFAULT_START_INDEX =
0
Instance Attribute Summary collapse
-
#end_index ⇒ Object
readonly
Returns the value of attribute end_index.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
-
#start_index ⇒ Object
readonly
Returns the value of attribute start_index.
Instance Method Summary collapse
-
#initialize(separator: DEFAULT_SEPARATOR, start_index: DEFAULT_START_INDEX, end_index: DEFAULT_END_INDEX) ⇒ Join
constructor
A new instance of Join.
- #transform(_resolver, value, _time, _record) ⇒ Object
Methods included from Arrays
Constructor Details
#initialize(separator: DEFAULT_SEPARATOR, start_index: DEFAULT_START_INDEX, end_index: DEFAULT_END_INDEX) ⇒ Join
Returns a new instance of Join.
25 26 27 28 29 30 31 32 |
# 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 |
Instance Attribute Details
#end_index ⇒ Object (readonly)
Returns the value of attribute end_index.
23 24 25 |
# File 'lib/realize/collection/join.rb', line 23 def end_index @end_index end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
23 24 25 |
# File 'lib/realize/collection/join.rb', line 23 def separator @separator end |
#start_index ⇒ Object (readonly)
Returns the value of attribute start_index.
23 24 25 |
# File 'lib/realize/collection/join.rb', line 23 def start_index @start_index end |
Instance Method Details
#transform(_resolver, value, _time, _record) ⇒ Object
34 35 36 37 38 |
# 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 |