Class: Lookout::Diff::Formats::Unified::ToS

Inherits:
Object
  • Object
show all
Defined in:
lib/lookout-3.0/diff/formats/unified.rb

Instance Method Summary collapse

Constructor Details

#initialize(group) ⇒ ToS

Returns a new instance of ToS.



36
# File 'lib/lookout-3.0/diff/formats/unified.rb', line 36

def initialize(group) @group = group end

Instance Method Details

#copy(operation) ⇒ Object



38
# File 'lib/lookout-3.0/diff/formats/unified.rb', line 38

def copy(operation) mark(' ', operation.old) end

#delete(operation) ⇒ Object



37
# File 'lib/lookout-3.0/diff/formats/unified.rb', line 37

def delete(operation) mark('-', operation.old) end

#insert(operation) ⇒ Object



39
# File 'lib/lookout-3.0/diff/formats/unified.rb', line 39

def insert(operation) mark('+', operation.new) end

#replace(operation) ⇒ Object



40
# File 'lib/lookout-3.0/diff/formats/unified.rb', line 40

def replace(operation) delete(operation).concat(insert(operation)) end

#to_sObject



42
43
44
45
46
47
48
49
50
# File 'lib/lookout-3.0/diff/formats/unified.rb', line 42

def to_s
  lines = ['@@ -%d,%d +%d,%d @@' %
           [@group.old.begin + 1, @group.old.size,
            @group.new.begin + 1, @group.new.size]]
  @group.each do |operation|
    lines.concat operation.apply(self)
  end
  lines.join("\n")
end