Drops.Inflector.Rules (drops_inflector v0.1.0)

View Source

A set of inflection rules that can be applied to words.

This module manages a list of rules (patterns and replacements) that are applied in order until one matches and transforms the input word.

Summary

Functions

Applies the rules to a word, returning the transformed word.

Iterates over all rules, calling the given function for each rule.

Inserts a rule at the specified index.

Creates a new empty Rules struct.

Types

rule()

@type rule() :: {Regex.t() | String.t(), String.t()}

t()

@type t() :: %Drops.Inflector.Rules{rules: [rule()]}

Functions

apply_to(rules, word)

@spec apply_to(t(), String.t()) :: String.t()

Applies the rules to a word, returning the transformed word.

Rules are applied in order until one matches and transforms the word. If no rules match, the original word is returned.

each(rules, fun)

@spec each(t(), (rule() -> any())) :: :ok

Iterates over all rules, calling the given function for each rule.

insert(struct, index, rule)

@spec insert(t(), non_neg_integer(), rule()) :: t()

Inserts a rule at the specified index.

new()

@spec new() :: t()

Creates a new empty Rules struct.