Class: Cure::Strategy::BaseStrategy

Inherits:
Object
  • Object
show all
Includes:
History
Defined in:
lib/cure/strategy/base_strategy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from History

#history, #reset_history, #retrieve_history, #store_history

Constructor Details

#initialize(params) ⇒ BaseStrategy

Returns a new instance of BaseStrategy.



16
17
18
19
20
# File 'lib/cure/strategy/base_strategy.rb', line 16

def initialize(params)
  # Is there a better way to do this? If its a base, we take a {}, if super
  # defines it, we just use that instance.
  @params = params.is_a?(Hash) ? BaseStrategyParams.new(params) : params
end

Instance Attribute Details

#paramsBaseStrategyParams

Additional details needed to make substitution.

Returns:



14
15
16
# File 'lib/cure/strategy/base_strategy.rb', line 14

def params
  @params
end

Instance Method Details

#describeObject



42
43
44
# File 'lib/cure/strategy/base_strategy.rb', line 42

def describe
  _describe
end

#extract(source_value, row_ctx, generator) ⇒ String

This will retrieve the (partial) value, then generate a new replacement.

Parameters:

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cure/strategy/base_strategy.rb', line 28

def extract(source_value, row_ctx, generator)
  extracted_value = _retrieve_value(source_value)
  existing = retrieve_history(extracted_value)

  return _replace_value(source_value, existing) if existing && !@params.force_replace

  generated_value = generator.generate(source_value, row_ctx)&.to_s
  value = _replace_value(source_value, generated_value)

  store_history(extracted_value, generated_value)

  value
end