Class: Lookout::Diff::Algorithms::Difflib::Position

Inherits:
Object
  • Object
show all
Defined in:
lib/lookout-3.0/diff/algorithms/difflib/position.rb

Overview

Keeps track of a position into the two sequences currently being “diffed” of the difflib algorithm and generates matches and new positions based on this position.

Defined Under Namespace

Classes: New

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.origin(old, new) ⇒ Object



12
13
14
15
16
17
# File 'lib/lookout-3.0/diff/algorithms/difflib/position.rb', line 12

def origin(old, new)
  new = New.new(new)
  new(Lookout::Diff::Slice.new(old),
      new,
      block_given? ? new.indexes.reduce({}){ |j, (k, _)| j[k] = yield(k); j } : {})
end

Instance Method Details

#begin_after(match) ⇒ Object



23
# File 'lib/lookout-3.0/diff/algorithms/difflib/position.rb', line 23

def begin_after(match) self.class.new(old.begin_after(match.old), new.begin_after(match.new), junk) end

#begin_before?(match) ⇒ Boolean

Returns:

  • (Boolean)


21
# File 'lib/lookout-3.0/diff/algorithms/difflib/position.rb', line 21

def begin_before?(match) old.begin_before? match.old and new.begin_before? match.new end

#end_after?(match) ⇒ Boolean

Returns:

  • (Boolean)


22
# File 'lib/lookout-3.0/diff/algorithms/difflib/position.rb', line 22

def end_after?(match) old.end_after? match.old and new.end_after? match.new end

#end_before(match) ⇒ Object



24
# File 'lib/lookout-3.0/diff/algorithms/difflib/position.rb', line 24

def end_before(match) self.class.new(old.end_before(match.old), new.end_before(match.new), junk) end

#inspectObject



25
# File 'lib/lookout-3.0/diff/algorithms/difflib/position.rb', line 25

def inspect; '#<%s %p,%p>' % [self.class, old, new] end

#matchObject



20
# File 'lib/lookout-3.0/diff/algorithms/difflib/position.rb', line 20

def match; junk.empty? ? leftmost_longest : expand(expand(leftmost_longest, false), true) end