module

Similar

Constants

VERSION = "0.1.0"

Class methods

capture_diff(alg : Algorithm, old, old_range : Range(Int32, Int32), new, new_range : Range(Int32, Int32)) : Array(DiffOp)

Creates a diff between old and new with the given algorithm capturing the ops.

This is like diff but instead of using an arbitrary hook this will always use Compact + Replace + Capture and return the captured DiffOps.

Source
capture_diff_deadline(alg : Algorithm, old, old_range : Range(Int32, Int32), new, new_range : Range(Int32, Int32), deadline = nil) : Array(DiffOp)

Creates a diff between old and new with the given algorithm capturing the ops.

Works like capture_diff but with an optional deadline.

Source
capture_diff_slices(alg : Algorithm, old, new) : Array(DiffOp)

Creates a diff between old and new with the given algorithm capturing the ops.

Source
capture_diff_slices_deadline(alg : Algorithm, old, new, deadline = nil) : Array(DiffOp)

Creates a diff between old and new with the given algorithm capturing the ops.

Works like capture_diff_slices but with an optional deadline.

Source
get_close_matches(word : String, possibilities : Array(String), n : Int32, cutoff : Float32) : Array(String)

Return a list of the best "good enough" matches.

word is a sequence for which close matches are desired (typically a string). possibilities is a list of sequences against which to match word (typically a list of strings). n (default 3) is the maximum number of close matches to return; n must be greater than 0. cutoff (default 0.6) is a float in the range [0, 1]. Possibilities that don't score at least that similar to word are ignored.

require "similar"

matches = Similar.get_close_matches("appel", ["ape", "apple", "peach", "puppy"], 3, 0.6)
matches.should eq(["apple", "ape"])

Requires the text feature.

Source
get_diff_ratio(ops : Array(DiffOp), old_len : Int32, new_len : Int32) : Float32

Return a measure of similarity in the range 0..=1.

A ratio of 1.0 means the two sequences are a complete match, a ratio of 0.0 would indicate completely distinct sequences. The input is the sequence of diff operations and the length of the old and new sequence.

Source
group_diff_ops(ops : Array(DiffOp), n : Int32) : Array(Array(DiffOp))

Isolate change clusters by eliminating ranges with no changes.

This will leave holes behind in long periods of equal ranges so that you can build things like unified diffs.

Source
iter_inline_changes(diff : TextDiff(T), op : DiffOp) : Array(InlineChange) forall T

Iterates over inline changes for a diff operation.

Source

Nested types