Class: Diff::LCS::Block
- Inherits:
-
Object
- Object
- Diff::LCS::Block
- Defined in:
- lib/diff/lcs/block.rb
Overview
A block is an operation removing, adding, or changing a group of items. Basically, this is just a list of changes, where each change adds or deletes a single item. Used by bin/ldiff.
Instance Attribute Summary (collapse)
-
- (Object) changes
readonly
Returns the value of attribute changes.
-
- (Object) insert
readonly
Returns the value of attribute insert.
-
- (Object) remove
readonly
Returns the value of attribute remove.
Instance Method Summary (collapse)
- - (Object) diff_size
-
- (Block) initialize(chunk)
constructor
A new instance of Block.
- - (Object) op
Constructor Details
- (Block) initialize(chunk)
A new instance of Block
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/diff/lcs/block.rb', line 15 def initialize(chunk) @changes = [] @insert = [] @remove = [] chunk.each do |item| @changes << item @remove << item if item.deleting? @insert << item if item.adding? end end |
Instance Attribute Details
- (Object) changes (readonly)
Returns the value of attribute changes
13 14 15 |
# File 'lib/diff/lcs/block.rb', line 13 def changes @changes end |
- (Object) insert (readonly)
Returns the value of attribute insert
13 14 15 |
# File 'lib/diff/lcs/block.rb', line 13 def insert @insert end |
- (Object) remove (readonly)
Returns the value of attribute remove
13 14 15 |
# File 'lib/diff/lcs/block.rb', line 13 def remove @remove end |
Instance Method Details
- (Object) diff_size
27 28 29 |
# File 'lib/diff/lcs/block.rb', line 27 def diff_size @insert.size - @remove.size end |
- (Object) op
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/diff/lcs/block.rb', line 31 def op case [@remove.empty?, @insert.empty?] when [false, false] '!' when [false, true] '-' when [true, false] '+' else # [true, true] '^' end end |