Wordsmith::Inflector::Inflections
Create and manipulate the set of valid Wordsmith inflections.
Constructors
Instance methods
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"
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:humansTODO: This arg should be an enum
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"
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"
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"
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"
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"