Class: DiffViewer
- Inherits:
-
Object
- Object
- DiffViewer
- Defined in:
- lib/diffviewer.rb
Overview
指定されたソースの差分を作成する
書式はなんちゃってunified contextなので、パッチ作成には使えません
Defined Under Namespace
Classes: InvalidSourceType
Instance Method Summary collapse
-
#initialize(old, new, source = :file) ⇒ DiffViewer
constructor
A new instance of DiffViewer.
- #to_s ⇒ Object
- #view ⇒ Object
Constructor Details
#initialize(old, new, source = :file) ⇒ DiffViewer
Returns a new instance of DiffViewer.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/diffviewer.rb', line 16 def initialize(old, new, source = :file) case source when :file old_strings = File.read(old, :encoding => Encoding::UTF_8) new_strings = File.read(new, :encoding => Encoding::UTF_8) when :string old_strings = old new_strings = new else raise InvalidSourceType, "source supported options are ':file' and ':string'" end old_strings.gsub!("\r", "") new_strings.gsub!("\r", "") @builded_buffer = "" @events = Diff::LCS.sdiff(old_strings.split("\n"), new_strings.split("\n")) build end |
Instance Method Details
#to_s ⇒ Object
34 35 36 |
# File 'lib/diffviewer.rb', line 34 def to_s @builded_buffer end |
#view ⇒ Object
38 39 40 |
# File 'lib/diffviewer.rb', line 38 def view puts @builded_buffer end |