Method: DiffViewer#initialize
- Defined in:
- lib/diffviewer.rb
#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 |