Class: Lookout::Diff::Operations::Copy

Inherits:
Lookout::Diff::Operation show all
Defined in:
lib/lookout-3.0/diff/operations/copy.rb

Overview

Slice that should be copied from the old sequence.

Instance Method Summary collapse

Methods inherited from Lookout::Diff::Operation

#apply

Instance Method Details

#<<(context) ⇒ Object

Note:

Logically, the receiver should be #foldable? inside CONTEXT, but this isn’t enforced.

Folds from the end of the receiver, leaving CONTEXT elements.

Parameters:

  • context (Integer)


18
19
20
21
# File 'lib/lookout-3.0/diff/operations/copy.rb', line 18

def <<(context)
  self.class.new(old.end_at([old.end, old.begin + context - 1].min),
                 new.end_at([new.end, new.begin + context - 1].min))
end

#>>(context) ⇒ Object

Note:

Logically, the receiver should be #foldable? inside CONTEXT, but this isn’t enforced.

Folds from the beginning of the receiver, leaving CONTEXT elements.

Parameters:

  • context (Integer)


12
13
14
15
# File 'lib/lookout-3.0/diff/operations/copy.rb', line 12

def >>(context)
  self.class.new(old.begin_at([old.begin, old.end - context + 1].max),
                 new.begin_at([new.begin, new.end - context + 1].max))
end

#foldable?(context) ⇒ Boolean

Returns True if the slice of the old sequence is larger than CONTEXT * 2 (#old#size > CONTEXT * 2) so that it may be folded to CONTEXT at both ends (#>>, #<<).

Parameters:

  • context (Integer)

Returns:

  • (Boolean)

    True if the slice of the old sequence is larger than CONTEXT * 2 (#old#size > CONTEXT * 2) so that it may be folded to CONTEXT at both ends (#>>, #<<)



9
# File 'lib/lookout-3.0/diff/operations/copy.rb', line 9

def foldable?(context) old.size > context * 2 end

#parity?Boolean

Returns True if #old ‘#==` #new.

Returns:

  • (Boolean)

    True if #old ‘#==` #new



24
# File 'lib/lookout-3.0/diff/operations/copy.rb', line 24

def parity?; old == new end