class

Similar::UnifiedDiff(T)

Inherits Reference < Object

Unified diff formatter.

Example:

old_text = "Hello\nWorld"
new_text = "Hello\nCrystal"
diff = TextDiff.from_lines(old_text, new_text)
puts diff.unified_diff.header("old.txt", "new.txt")

Constructors

new(diff : TextDiff(T))

Creates a formatter from a text diff object.

Source

Instance methods

context_radius(n : Int32) : self

Changes the context radius.

The context radius is the number of lines between changes that should be emitted. This defaults to 3.

Source
header(a : String, b : String) : self

Sets a header to the diff.

a and b are the file names that are added to the top of the unified file format. The names are accepted verbatim which lets you encode a timestamp into it when separated by a tab (\t).

Source
header_opt(header : Tuple(String, String) | Nil) : self

Internal method to set header optionally.

Source
iter_hunks

Iterates over all hunks as configured.

Source
missing_newline_hint(yes : Bool) : self

Controls the missing newline hint.

By default a special \ No newline at end of file marker is added to the output when a file is not terminated with a final newline. This can be disabled with this flag.

Source
to_s(io : IO) : Nil

Returns the unified diff as a string.

Source
to_writer(io : IO) : Nil

Write the unified diff as bytes to the output stream.

Source