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

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

Defined Under Namespace

Classes: To

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to, junk) ⇒ Position

Returns a new instance of Position.



17
18
19
# File 'lib/lookout/diff/algorithms/difflib/position.rb', line 17

def initialize(from, to, junk)
  @from, @to, @junk = from, to, junk
end

Class Method Details

.origin(from, to) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/lookout/diff/algorithms/difflib/position.rb', line 7

def origin(from, to)
  to = To.new(to)
  new(Lookout::Diff::Range.new(from),
      to,
      block_given? ?
        to.indexes.reduce({}){ |j, (k, _)| j[k] = yield(k); j } :
        {})
end

Instance Method Details

#==(other) ⇒ Object



42
43
44
# File 'lib/lookout/diff/algorithms/difflib/position.rb', line 42

def ==(other)
  from == other.from and to == other.to and junk == other.junk
end

#begin_after(match) ⇒ Object



34
35
36
# File 'lib/lookout/diff/algorithms/difflib/position.rb', line 34

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

#begins_before?(match) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/lookout/diff/algorithms/difflib/position.rb', line 26

def begins_before?(match)
  from.begins_before? match.from and to.begins_before? match.to
end

#end_before(match) ⇒ Object



38
39
40
# File 'lib/lookout/diff/algorithms/difflib/position.rb', line 38

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

#ends_after?(match) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/lookout/diff/algorithms/difflib/position.rb', line 30

def ends_after?(match)
  from.ends_after? match.from and to.ends_after? match.to
end

#inspectObject



46
47
48
# File 'lib/lookout/diff/algorithms/difflib/position.rb', line 46

def inspect
  '#<%s %p,%p>' % [self.class, from, to]
end

#matchObject



21
22
23
24
# File 'lib/lookout/diff/algorithms/difflib/position.rb', line 21

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