Class: Diffing::Diff
- Inherits:
-
Object
- Object
- Diffing::Diff
- Defined in:
- lib/diffing/diff.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #format(format = Format::Ascii) ⇒ Object
-
#initialize(from, to, delimiter = '') ⇒ Diff
constructor
A new instance of Diff.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(from, to, delimiter = '') ⇒ Diff
Returns a new instance of Diff.
8 9 10 11 |
# File 'lib/diffing/diff.rb', line 8 def initialize( from, to, delimiter = '' ) @delimiter = delimiter @parts = calcucate( split( from.to_s ), split( to.to_s ) ).flatten end |
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
6 7 8 |
# File 'lib/diffing/diff.rb', line 6 def parts @parts end |
Instance Method Details
#format(format = Format::Ascii) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/diffing/diff.rb', line 13 def format( format = Format::Ascii ) result = [] @parts.each do |part| result << format.source( part.source ) if part.source? if part.replace? and format.respond_to?( :replace ) result << format.replace( part.delete, part.insert ) else result << format.insert( part.insert ) if part.insert? result << format.delete( part.delete ) if part.delete? end end result.join @delimiter end |
#inspect ⇒ Object
31 32 33 |
# File 'lib/diffing/diff.rb', line 31 def inspect format end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/diffing/diff.rb', line 27 def to_s format end |