class Wordsmith::Inflector::Inflections

Overview

Create and manipulate the set of valid Wordsmith inflections.

Defined in:

wordsmith/inflector/inflections.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

Create a new object to store the collection of inflectable words and patterns.


[View source]

Instance Method Detail

def acronym(word) #

Define a new acronym that should be recognized.

Example:

Wordsmith::Inflector.inflections.acronym("API")
Wordsmith::Inflector.camelize("API")   # => "API"
Wordsmith::Inflector.underscore("API") # => "api"
Wordsmith::Inflector.humanize("API")   # => "API"
Wordsmith::Inflector.titleize("API")   # => "API"

[View source]
def acronym_regex : Regex #

Return the current set of acronym Regex patterns to recognize.


[View source]
def acronyms : Hash(String, String) #

Return the current set of acronym strings to recognize.


[View source]
def clear(scope = :all) #

Remove all currently-stored Inflection rules, or a subset of rules.

Subsets can be provided with the scope parameter, and can be any of:

  • :all
  • :plurals
  • :singulars
  • :uncountables
  • :humans

[View source]
def human(rule : String | Regex, replacement : String) #

Define a new humanize rule, either using a pattern or string.

Example with a Regex pattern:

Wordsmith::Inflector.inflections.human(/^prefix_/i, "\\1")
Wordsmith::Inflector.humanize("prefix_request") # => "Request"

Example with a String:

Wordsmith::Inflector.inflections.human("col_rpted_bugs", "Reported bugs")
Wordsmith::Inflector.humanize("col_rpted_bugs") # => "Reported bugs"

[View source]
def humans : Hash(Regex, String) #

Return the current set of items that can be humanized.


[View source]
def irregular(singular : String, plural : String) #

Define a new irregular String with a direct translation between singular and plural form.

Example:

Wordsmith::Inflector.inflections.irregular("person", "people")
Wordsmith::Inflector.singularize("people") # => "person"
Wordsmith::Inflector.pluralize("person")   # => "people"

[View source]
def plural(rule : String | Regex, replacement : String) #

Define a new pluralization rule, either using a pattern or string.

Example with a Regex pattern:

Wordsmith::Inflector.inflections.plural(/^goose(\S*)$/i, "geese\\1")
Wordsmith::Inflector.pluralize("goosebumps") # => "geesebumps"

Example with a String:

Wordsmith::Inflector.inflections.plural("goosebumps", "geesebumps")
Wordsmith::Inflector.pluralize("goosebumps") # => "geesebumps"

[View source]
def plurals : Hash(Regex, String) #

Return the current set of matched pluralization patterns.


[View source]
def singular(rule : String | Regex, replacement : String) #

Define a new singularization rule, either using a pattern or string.

Example with a Regex pattern:

Wordsmith::Inflector.inflections.singular(/^(ox)en$/i, "\\1")
Wordsmith::Inflector.singularize("oxen") # => "ox"

Example with a String:

Wordsmith::Inflector.inflections.singular("mice", "mouse")
Wordsmith::Inflector.singularize("mice") # => "mouse"

[View source]
def singulars : Hash(Regex, String) #

Return the current set of matched singularization patterns.


[View source]
def uncountable(*words) #

Define a new uncountable String that should stay the same between singular and plural form.

Example with a single String:

Wordsmith::Inflector.inflections.uncountable("jedi")
Wordsmith::Inflector.singularize("jedi") # => "jedi"
Wordsmith::Inflector.pluralize("jedi")   # => "jedi"

Example with a single String:

Wordsmith::Inflector.inflections.uncountable(%w(fish jedi))
Wordsmith::Inflector.singularize("jedi") # => "jedi"
Wordsmith::Inflector.pluralize("fish")   # => "fish"

[View source]

Return the current set of items considered uncountable.


[View source]