Class: DiffViewer

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

Overview

指定されたソースの差分を作成する

書式はなんちゃってunified contextなので、パッチ作成には使えません

Defined Under Namespace

Classes: InvalidSourceType

Instance Method Summary collapse

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

#resultObject



35
36
37
# File 'lib/diffviewer.rb', line 35

def result
  @builded_buffer
end