Class: DiffLCS::Counter
- Inherits:
-
Object
- Object
- DiffLCS::Counter
- Includes:
- Comparable
- Defined in:
- lib/diff_l_c_s/counter.rb
Overview
–# Copyright: © 2006-2008 The LogiLogi Foundation <[email protected]>
License:
This file is part of the DiffLCS library. DiffLCS is Free Software.
You can run/distribute/modify DiffLCS under the terms of the GNU Affero
General Public License version 3. The Affero GPL states that running a
modified version or a derivative work also requires you to make the
sourcecode of that work available to everyone that can interact with it.
We chose the Affero GPL to ensure that DiffLCS remains open and libre
(LICENSE.txt contains the full text of the legally binding license).
++#
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compares it’s own size with the size of the other.
-
#in_new ⇒ Object
Returns the PositionRange for the range in the new string.
-
#in_new=(new_in_new) ⇒ Object
Sets the in_new PositionRange, and updates the in_old too.
-
#in_old ⇒ Object
Returns the PositionRange for the range in the old string.
-
#in_old=(new_in_old) ⇒ Object
Sets the in_old PositionRange, and updates the in_new too.
-
#initialize(old_i, new_i) ⇒ Counter
constructor
Creates a new counter and sets the initial positions and size.
-
#size ⇒ Object
Returns the size of this Counter.
-
#step_size ⇒ Object
Faster than size, but only tells the size to which was stepped.
-
#step_up ⇒ Object
Increases the size.
Constructor Details
#initialize(old_i, new_i) ⇒ Counter
Creates a new counter and sets the initial positions and size
19 20 21 22 23 |
# File 'lib/diff_l_c_s/counter.rb', line 19 def initialize(old_i, new_i) @in_old_begin = old_i @in_new_begin = new_i @size = 1 end |
Instance Method Details
#<=>(other) ⇒ Object
Compares it’s own size with the size of the other
105 106 107 |
# File 'lib/diff_l_c_s/counter.rb', line 105 def <=> (other) return self.size <=> other.size end |
#in_new ⇒ Object
Returns the PositionRange for the range in the new string
NOTE: No step_up’s possible anymore after this function has been called.
49 50 51 52 53 54 |
# File 'lib/diff_l_c_s/counter.rb', line 49 def in_new if !@in_new @in_new = PositionRange.new(@in_new_begin, @in_new_begin + @size) end return @in_new end |
#in_new=(new_in_new) ⇒ Object
Sets the in_new PositionRange, and updates the in_old too
If new_in_old is nil, the counter is set empty
NOTE: Assumed to be smaller than before, and not moved.
77 78 79 80 81 82 83 84 |
# File 'lib/diff_l_c_s/counter.rb', line 77 def in_new=(new_in_new) if new_in_new @in_old = self.adjust(self.in_old, self.in_new, new_in_new) @in_new = new_in_new else @empty = true end end |
#in_old ⇒ Object
Returns the PositionRange for the range in the old string.
NOTE: No step_up’s possible anymore after this function has been called.
37 38 39 40 41 42 |
# File 'lib/diff_l_c_s/counter.rb', line 37 def in_old if !@in_old @in_old = PositionRange.new(@in_old_begin, @in_old_begin + @size) end return @in_old end |
#in_old=(new_in_old) ⇒ Object
Sets the in_old PositionRange, and updates the in_new too
If new_in_old is nil, the counter is set empty
NOTE: Assumed to be smaller than before, and not moved.
62 63 64 65 66 67 68 69 |
# File 'lib/diff_l_c_s/counter.rb', line 62 def in_old=(new_in_old) if new_in_old @in_new = self.adjust(self.in_new, self.in_old, new_in_old) @in_old = new_in_old else @empty = true end end |
#size ⇒ Object
Returns the size of this Counter
95 96 97 98 99 100 101 |
# File 'lib/diff_l_c_s/counter.rb', line 95 def size if @empty return 0 else return self.in_old.size end end |
#step_size ⇒ Object
Faster than size, but only tells the size to which was stepped.
89 90 91 |
# File 'lib/diff_l_c_s/counter.rb', line 89 def step_size return @size end |
#step_up ⇒ Object
Increases the size
27 28 29 30 |
# File 'lib/diff_l_c_s/counter.rb', line 27 def step_up @size += 1 return self end |