module Abbrev

Overview

Calculates the set of unambiguous abbreviations for a given set of strings.

This module is a straightforward port of Ruby's Abbrev.

Extended Modules

Defined in:

abbrev.cr
abbrev/version.cr

Constant Summary

VERSION = "0.1.0"

Instance Method Summary

Instance Method Detail

def abbrev(words : Enumerable(String), pattern : Regex | Nil = nil) #

Generates a table of unambiguous abbreviations for each word in words.

If pattern is given, then only those abbreviations that match the pattern are included in the table.

Returns a Hash containing the mappings of abbreviations to words.

Abbrev.abbrev(%w{crystal})
# => {"crystal" => "crystal", "crysta" => "crystal", "cryst" => "crystal", "crys" => "crystal", "cry" => "crystal", "cr" => "crystal", "c" => "crystal"}

Abbrev.abbrev(%w{crystal ruby}, /^r/)
# => {"ruby" => "ruby", "rub" => "ruby", "ru" => "ruby", "r" => "ruby"}

[View source]