Class: Cure::Strategy::BaseStrategy
- Inherits:
-
Object
- Object
- Cure::Strategy::BaseStrategy
- Includes:
- History
- Defined in:
- lib/cure/strategy/base_strategy.rb
Direct Known Subclasses
AppendStrategy, EndWithStrategy, FullStrategy, MatchStrategy, RegexStrategy, SplitStrategy, StartWithStrategy
Instance Attribute Summary collapse
-
#params ⇒ BaseStrategyParams
Additional details needed to make substitution.
Instance Method Summary collapse
-
#extract(source_value, 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.
53 54 55 56 57 |
# File 'lib/cure/strategy/base_strategy.rb', line 53 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.
51 52 53 |
# File 'lib/cure/strategy/base_strategy.rb', line 51 def params @params end |
Instance Method Details
#extract(source_value, generator) ⇒ String
This will retrieve the (partial) value, then generate a new replacement.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cure/strategy/base_strategy.rb', line 64 def extract(source_value, generator) extracted_value = _retrieve_value(source_value) existing = retrieve_history(extracted_value) return _replace_value(source_value, existing) if existing generated_value = generator.generate(source_value)&.to_s value = _replace_value(source_value, generated_value) store_history(extracted_value, generated_value) value end |