Class: Diff::LCS::Block
- Inherits:
-
Data
- Object
- Data
- Diff::LCS::Block
- Defined in:
- lib/diff/lcs/block.rb,
lib/diff/lcs/block.rb
Overview
A block is an operation removing, adding, or changing a group of items, a list of changes, where each change adds or deletes a single item.
Used by bin/ldiff.
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#insert ⇒ Object
readonly
Returns the value of attribute insert.
-
#remove ⇒ Object
readonly
Returns the value of attribute remove.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#changes ⇒ Object (readonly)
Returns the value of attribute changes
3 4 5 |
# File 'lib/diff/lcs/block.rb', line 3 def changes @changes end |
#insert ⇒ Object (readonly)
Returns the value of attribute insert
3 4 5 |
# File 'lib/diff/lcs/block.rb', line 3 def insert @insert end |
#remove ⇒ Object (readonly)
Returns the value of attribute remove
3 4 5 |
# File 'lib/diff/lcs/block.rb', line 3 def remove @remove end |
Class Method Details
.from_chunk(chunk) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/diff/lcs/block.rb', line 10 def self.from_chunk(chunk) changes, insert, remove = [], [], [] chunk.each do changes << _1 remove << _1 if _1.deleting? insert << _1 if _1.adding? end new(changes: changes.freeze, remove: remove.freeze, insert: insert.freeze) end |
Instance Method Details
#diff_size ⇒ Object
28 |
# File 'lib/diff/lcs/block.rb', line 28 def diff_size = insert.size - remove.size |
#op ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/diff/lcs/block.rb', line 30 def op case [remove, insert] # Unchanged in [[], []] then "^" # Delete in [_, []] then "-" # Insert in [[], _] then "+" # Conflict in [_, _] then "!" end end |