Class: TrajectPlus::Indexer::ComposeStep
- Inherits:
-
ToFieldStep
- Object
- Traject::Indexer::ToFieldStep
- ToFieldStep
- TrajectPlus::Indexer::ComposeStep
- Defined in:
- lib/traject_plus/indexer/step.rb
Instance Attribute Summary collapse
-
#indexer ⇒ Object
readonly
Returns the value of attribute indexer.
Instance Method Summary collapse
- #execute(context) ⇒ Object
-
#initialize(fieldname, lambda, block, source_location, indexer) ⇒ ComposeStep
constructor
A new instance of ComposeStep.
Methods inherited from ToFieldStep
add_accumulator_to_context!, #add_accumulator_to_context!, #single?, #to_field_step?
Constructor Details
#initialize(fieldname, lambda, block, source_location, indexer) ⇒ ComposeStep
Returns a new instance of ComposeStep.
41 42 43 44 45 46 47 |
# File 'lib/traject_plus/indexer/step.rb', line 41 def initialize(fieldname, lambda, block, source_location, indexer) @indexer = indexer self.field_name = fieldname self.lambda = lambda self.block = block self.source_location = source_location end |
Instance Attribute Details
#indexer ⇒ Object (readonly)
Returns the value of attribute indexer.
39 40 41 |
# File 'lib/traject_plus/indexer/step.rb', line 39 def indexer @indexer end |
Instance Method Details
#execute(context) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/traject_plus/indexer/step.rb', line 49 def execute(context) accumulator = [] if lambda lambda.call(context.source_record, accumulator, context) else accumulator << context.source_record end accumulator.map do |record| result = indexer.map_record(record) if field_name self.class.add_accumulator_to_context! self, field_name, [result], context else result.each do |k, v| self.class.add_accumulator_to_context! self, k, Array(v), context end end end end |