Class: Cure::Strategy::SplitStrategy

Inherits:
BaseStrategy show all
Defined in:
lib/cure/strategy/split_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) ⇒ SplitStrategy

Returns a new instance of SplitStrategy.



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

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

Instance Attribute Details

#paramsSplitStrategyParams

Additional details needed to make substitution.

Returns:



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

def params
  @params
end

Instance Method Details

#_describeObject



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

def _describe
  "Splitting on '#{@params.token}', at index #{@params.index}) " \
  "[Note: If the value does not include '#{@params.token}', no substitution is made.]"
end

#_replace_value(source_value, generated_value) ⇒ String

Parameters:

Returns:



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

def _replace_value(source_value, generated_value)
  split_token = @params.token

  return unless source_value.include?(split_token)

  result_arr = source_value.split(split_token)
  result_arr[@params.index] = generated_value if value?(result_arr[@params.index])
  result_arr.join(split_token)
end

#_retrieve_value(source_value) ⇒ Object

Parameters:



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

def _retrieve_value(source_value)
  return unless source_value.include?(@params.token)

  result_arr = source_value.split(@params.token)
  result_arr[@params.index]
end