Fuzzyurl.Match

Summary

Functions

From a list of Fuzzyurl masks, returns the one which best matches url. Returns nil if none of masks match

Returns 0 for wildcard match, 1 for exact match, or :no_match otherwise

Returns an integer representing how closely mask (which may have wildcards) resembles url (which may not), or :no_match in the case of a conflict

Returns a Fuzzyurl struct containing values representing how well different parts of mask and url match. Values are integer; higher values indicate closer matches

Returns true if mask (which may contain wildcards) matches url (which may not), or false otherwise

Functions

best_match(masks, url)

From a list of Fuzzyurl masks, returns the one which best matches url. Returns nil if none of masks match.

iex> masks = [Fuzzyurl.mask(path: "/foo/*"), Fuzzyurl.mask(path: "/foo/bar"), Fuzzyurl.mask]
iex> Fuzzyurl.Match.best_match(masks, Fuzzyurl.from_string("http://exmaple.com/foo/bar"))
%Fuzzyurl{fragment: "*", hostname: "*", password: "*", path: "/foo/bar", port: "*", protocol: "*", query: "*", username: "*"}
fuzzy_match(mask, value)

Specs

fuzzy_match(String.t, String.t) :: 0 | 1 | :no_match

Returns 0 for wildcard match, 1 for exact match, or :no_match otherwise.

Wildcard language:

*              matches anything
foo/*          matches "foo/" and "foo/bar/baz" but not "foo"
foo/**         matches "foo/" and "foo/bar/baz" and "foo"
*.example.com  matches "api.v1.example.com" but not "example.com"
**.example.com matches "api.v1.example.com" and "example.com"

Any other form is treated as a literal match.

match(mask, url)

Specs

match(%Fuzzyurl{fragment: term, hostname: term, password: term, path: term, port: term, protocol: term, query: term, username: term}, %Fuzzyurl{fragment: term, hostname: term, password: term, path: term, port: term, protocol: term, query: term, username: term}) ::
  non_neg_integer |
  :no_match

Returns an integer representing how closely mask (which may have wildcards) resembles url (which may not), or :no_match in the case of a conflict.

match_scores(mask, url)

Specs

match_scores(%Fuzzyurl{fragment: term, hostname: term, password: term, path: term, port: term, protocol: term, query: term, username: term}, %Fuzzyurl{fragment: term, hostname: term, password: term, path: term, port: term, protocol: term, query: term, username: term}) :: %Fuzzyurl{fragment: term, hostname: term, password: term, path: term, port: term, protocol: term, query: term, username: term}

Returns a Fuzzyurl struct containing values representing how well different parts of mask and url match. Values are integer; higher values indicate closer matches.

matches?(mask, url)

Specs

matches?(%Fuzzyurl{fragment: term, hostname: term, password: term, path: term, port: term, protocol: term, query: term, username: term}, %Fuzzyurl{fragment: term, hostname: term, password: term, path: term, port: term, protocol: term, query: term, username: term}) :: boolean

Returns true if mask (which may contain wildcards) matches url (which may not), or false otherwise.