class Wordsmith::Inflector::Inflections
- Wordsmith::Inflector::Inflections
- Reference
- Object
Overview
Create and manipulate the set of valid Wordsmith inflections.
Defined in:
wordsmith/inflector/inflections.crConstructors
-
.new
Create a new object to store the collection of inflectable words and patterns.
Instance Method Summary
-
#acronym(word)
Define a new acronym that should be recognized.
-
#acronym_regex : Regex
Return the current set of acronym
Regex
patterns to recognize. -
#acronyms : Hash(String, String)
Return the current set of acronym strings to recognize.
-
#clear(scope = :all)
Remove all currently-stored Inflection rules, or a subset of rules.
-
#human(rule : String | Regex, replacement : String)
Define a new humanize rule, either using a pattern or string.
-
#humans : Hash(Regex, String)
Return the current set of items that can be humanized.
-
#irregular(singular : String, plural : String)
Define a new irregular
String
with a direct translation between singular and plural form. -
#plural(rule : String | Regex, replacement : String)
Define a new pluralization rule, either using a pattern or string.
-
#plurals : Hash(Regex, String)
Return the current set of matched pluralization patterns.
-
#singular(rule : String | Regex, replacement : String)
Define a new singularization rule, either using a pattern or string.
-
#singulars : Hash(Regex, String)
Return the current set of matched singularization patterns.
-
#uncountable(*words)
Define a new uncountable
String
that should stay the same between singular and plural form. -
#uncountables : Wordsmith::Inflector::Inflections::Uncountables
Return the current set of items considered uncountable.
Constructor Detail
Instance Method Detail
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
:humans
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"
Return the current set of items considered uncountable.