Class: Contrast::Agent::Assess::Policy::Propagator::Center

Inherits:
Base
  • Object
show all
Defined in:
lib/contrast/agent/assess/policy/propagator/center.rb

Overview

Propagation that results in all the tags of the source being applied to the target at its middle. The target’s preexisting tags are unaffected beyond any merging of overlapping tags.

Class Method Summary collapse

Methods inherited from Base

find_source, tracked_value?

Class Method Details

.propagate(propagation_node, preshift, target) ⇒ Object

propagation action required by this method.

Parameters:

Returns:

  • (Object)

    the target with the tags applied



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/contrast/agent/assess/policy/propagator/center.rb', line 19

def propagate propagation_node, preshift, target
  return unless (properties = Contrast::Agent::Assess::Tracker.properties!(target))

  sources = propagation_node.sources
  source1 = find_source(sources[0], preshift)

  if source1.length == target.length
    properties.copy_from(source1, target, 0, propagation_node.untags)
    properties.cleanup_tags
    return
  end

  # find original in the target, copy tags to the new position in target
  original_start_index = target[0..(target.length / 2) + 1].rindex(source1)
  original_start_index ||= 1
  properties.copy_from(source1, target, original_start_index, propagation_node.untags)

  return unless sources[1]

  original_end_index = original_start_index + source1.length - 1
  handle_incoming_tags(target, propagation_node, sources[1], preshift, original_start_index,
                       original_end_index)
end