Class: Lookout::Diff::Algorithms::Difflib::Position::New
- Inherits:
-
Slice
- Object
- Slice
- Lookout::Diff::Algorithms::Difflib::Position::New
show all
- Defined in:
- lib/lookout-3.0/diff/algorithms/difflib/position/new.rb
Instance Method Summary
collapse
Methods inherited from Slice
#+, #<=>, #[], #begin, #begin_at, #begin_before?, #each, #each_with_index, #empty?, #end, #end_after?, #end_at, #size, #to_items, #touch?
Constructor Details
#initialize(items, range = 0...items.size, indexes = nil) ⇒ New
Returns a new instance of New.
5
6
7
8
|
# File 'lib/lookout-3.0/diff/algorithms/difflib/position/new.rb', line 5
def initialize(items, range = 0...items.size, indexes = nil)
super items, range
@indexes = indexes
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
35
|
# File 'lib/lookout-3.0/diff/algorithms/difflib/position/new.rb', line 35
def ==(other) super and indexes == other.indexes end
|
#at(range) ⇒ Object
34
|
# File 'lib/lookout-3.0/diff/algorithms/difflib/position/new.rb', line 34
def at(range) Lookout::Diff::Slice.new(items, range) end
|
#begin_after(other) ⇒ Object
32
|
# File 'lib/lookout-3.0/diff/algorithms/difflib/position/new.rb', line 32
def begin_after(other) self.class.new(items, other.end + 1..self.end, indexes) end
|
#each_index(item) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/lookout-3.0/diff/algorithms/difflib/position/new.rb', line 10
def each_index(item)
indexes[item].each do |index|
next if index < range.begin
break if index > range.end
yield index
end
end
|
#end_before(other) ⇒ Object
33
|
# File 'lib/lookout-3.0/diff/algorithms/difflib/position/new.rb', line 33
def end_before(other) self.class.new(items, self.begin...other.begin, indexes) end
|
37
|
# File 'lib/lookout-3.0/diff/algorithms/difflib/position/new.rb', line 37
def hash; @hash ||= super ^ indexes.hash end
|
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/lookout-3.0/diff/algorithms/difflib/position/new.rb', line 18
def indexes
return @indexes if @indexes
@indexes = Hash.new{ |h, k| h[k] = [] }
each = items.is_a?(String) ?
(' '[0].is_a?(Integer) ? :each_byte : :each_char) :
:each
i = 0
items.send(each) do |item|
@indexes[item] << i
i += 1
end
@indexes
end
|