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.
- #result ⇒ Object
Constructor Details
#initialize(old, new, source = :file) ⇒ DiffViewer
Returns a new instance of DiffViewer.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/diffviewer.rb', line 17 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
#result ⇒ Object
35 36 37 |
# File 'lib/diffviewer.rb', line 35 def result @builded_buffer end |