Class: Diff::LCS::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/watobo/external/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

Instance Method Summary collapse

Constructor Details

#initialize(chunk) ⇒ Block

Returns a new instance of Block.



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/watobo/external/diff/lcs/block.rb', line 44

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

#changesObject (readonly)

Returns the value of attribute changes.



42
43
44
# File 'lib/watobo/external/diff/lcs/block.rb', line 42

def changes
  @changes
end

#insertObject (readonly)

Returns the value of attribute insert.



42
43
44
# File 'lib/watobo/external/diff/lcs/block.rb', line 42

def insert
  @insert
end

#removeObject (readonly)

Returns the value of attribute remove.



42
43
44
# File 'lib/watobo/external/diff/lcs/block.rb', line 42

def remove
  @remove
end

Instance Method Details

#diff_sizeObject



56
57
58
# File 'lib/watobo/external/diff/lcs/block.rb', line 56

def diff_size
  @insert.size - @remove.size
end

#opObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/watobo/external/diff/lcs/block.rb', line 60

def op
  case [@remove.empty?, @insert.empty?]
  when [false, false]
    '!'
  when [false, true]
    '-'
  when [true, false]
    '+'
  else # [true, true]
    '^'
  end
end