Class: Cure::Strategy::RegexStrategy

Inherits:
BaseStrategy show all
Defined in:
lib/cure/strategy/regex_strategy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseStrategy

#describe, #extract

Methods included from History

#history, #reset_history, #retrieve_history, #store_history

Constructor Details

#initialize(options) ⇒ RegexStrategy

Returns a new instance of RegexStrategy.



12
13
14
# File 'lib/cure/strategy/regex_strategy.rb', line 12

def initialize(options)
  super(RegexStrategyParams.new(options))
end

Instance Attribute Details

#paramsRegexStrategyParams

Additional details needed to make substitution.

Returns:



10
11
12
# File 'lib/cure/strategy/regex_strategy.rb', line 10

def params
  @params
end

Instance Method Details

#_describeObject



37
38
39
40
# File 'lib/cure/strategy/regex_strategy.rb', line 37

def _describe
  "Matching on '#{@params.regex_cg}'. " \
  "[Note: If the regex does not match, or has no capture group, no substitution is made.]"
end

#_replace_value(source_value, generated_value) ⇒ String

Parameters:

Returns:



28
29
30
31
32
33
34
35
# File 'lib/cure/strategy/regex_strategy.rb', line 28

def _replace_value(source_value, generated_value)
  m = /#{@params.regex_cg}/.match(source_value)
  return unless m.instance_of?(MatchData) && (!m[1].nil? && m[1] != "")

  generated_value unless replace_partial_record

  source_value.gsub(m[1], generated_value)
end

#_retrieve_value(source_value) ⇒ Object

gsub catchment group

Parameters:



18
19
20
21
22
23
# File 'lib/cure/strategy/regex_strategy.rb', line 18

def _retrieve_value(source_value)
  m = /#{@params.regex_cg}/.match(source_value)
  return unless m.instance_of?(MatchData) && (!m[1].nil? && m[1] != "")

  m[1]
end