Class: Cure::Strategy::BaseStrategy
- Inherits:
-
Object
- Object
- Cure::Strategy::BaseStrategy
- Includes:
- History
- Defined in:
- lib/cure/strategy/base_strategy.rb
Direct Known Subclasses
AppendStrategy, ContainStrategy, EndWithStrategy, FullStrategy, MatchStrategy, PrependStrategy, RegexStrategy, SplitStrategy, StartWithStrategy
Instance Attribute Summary collapse
-
#params ⇒ BaseStrategyParams
Additional details needed to make substitution.
Instance Method Summary collapse
- #describe ⇒ Object
-
#extract(source_value, row_ctx, generator) ⇒ String
This will retrieve the (partial) value, then generate a new replacement.
-
#initialize(params) ⇒ BaseStrategy
constructor
A new instance of BaseStrategy.
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
#params ⇒ BaseStrategyParams
Additional details needed to make substitution.
14 15 16 |
# File 'lib/cure/strategy/base_strategy.rb', line 14 def params @params end |
Instance Method Details
#describe ⇒ Object
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.
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 |