Class: CodeChange

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_diff/code_comparison.rb

Constant Summary collapse

OPERATION_CHARS =
{
  :added   => "+",
  :removed => "-",
  :changed => "c",
  :moved   => "m"   #Not used yet
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signature, operation, changes = []) ⇒ CodeChange



13
14
15
16
17
# File 'lib/ruby_diff/code_comparison.rb', line 13

def initialize(signature, operation, changes=[])
  @signature = signature
  @operation = operation
  @changes   = changes
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



4
5
6
# File 'lib/ruby_diff/code_comparison.rb', line 4

def changes
  @changes
end

#operationObject (readonly)

Returns the value of attribute operation.



3
4
5
# File 'lib/ruby_diff/code_comparison.rb', line 3

def operation
  @operation
end

#signatureObject (readonly)

Returns the value of attribute signature.



2
3
4
# File 'lib/ruby_diff/code_comparison.rb', line 2

def signature
  @signature
end

Instance Method Details

#to_s(depth = 1) ⇒ Object



19
20
21
22
23
# File 'lib/ruby_diff/code_comparison.rb', line 19

def to_s(depth=1)
  this_change = "#{OPERATION_CHARS[self.operation]}#{"  "*depth}#{signature}"
  sub_changes = changes.map{|c| c.to_s(depth+1)}
  [this_change, sub_changes].flatten.join("\n")
end