Class: TTY::File::Differ
- Inherits:
-
Object
- Object
- TTY::File::Differ
- Defined in:
- lib/tty/file/differ.rb
Instance Method Summary collapse
-
#call ⇒ String
Find character difference between two strings.
-
#initialize(string_a, string_b, options = {}) ⇒ Differ
constructor
Create a Differ.
Constructor Details
#initialize(string_a, string_b, options = {}) ⇒ Differ
Create a Differ
13 14 15 16 17 18 |
# File 'lib/tty/file/differ.rb', line 13 def initialize(string_a, string_b, = {}) @string_a = string_a @string_b = string_b @format = .fetch(:format, :unified) @context_lines = .fetch(:context_lines, 3) end |
Instance Method Details
#call ⇒ String
Find character difference between two strings
27 28 29 30 31 32 |
# File 'lib/tty/file/differ.rb', line 27 def call diffs = Diff::LCS.diff(string_a_lines, string_b_lines) return '' if diffs.empty? hunks = extract_hunks(diffs) format_hunks(hunks) end |