Class: Lookout::Diff::Match

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/lookout/diff/match.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to) ⇒ Match

Returns a new instance of Match.



6
7
8
# File 'lib/lookout/diff/match.rb', line 6

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

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



35
36
37
# File 'lib/lookout/diff/match.rb', line 35

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



35
36
37
# File 'lib/lookout/diff/match.rb', line 35

def to
  @to
end

Instance Method Details

#+(other) ⇒ Object



18
19
20
# File 'lib/lookout/diff/match.rb', line 18

def +(other)
  self.class.new(from + other.from, to + other.to)
end

#<=>(other) ⇒ Object



26
27
28
29
# File 'lib/lookout/diff/match.rb', line 26

def <=>(other)
  [from.begin, from.end, to.begin, to.end] <=>
    [other.from.begin, other.from.end, other.to.begin, other.to.end]
end

#empty?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/lookout/diff/match.rb', line 10

def empty?
  from.empty?
end

#inspectObject



31
32
33
# File 'lib/lookout/diff/match.rb', line 31

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

#sizeObject



14
15
16
# File 'lib/lookout/diff/match.rb', line 14

def size
  from.size
end

#touches?(other) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/lookout/diff/match.rb', line 22

def touches?(other)
  from.end + 1 == other.from.begin and to.end + 1 == other.to.begin
end