class Dry::Inflector::Inflections
- Dry::Inflector::Inflections
- Reference
- Object
Overview
Inflections
@since 0.1.0
Defined in:
dry/inflector/inflections.crdry/inflector/inflections/defaults.cr
Constructors
-
.build(&blk : self -> Nil) : Inflections
Instantiate a set of inflection rules.
- .build : Inflections
-
.new(&)
Instantiate the rules
- .new
Instance Method Summary
-
#acronym(words : Enumerable(String))
Add one or more acronyms
- #acronym(word)
-
#acronyms : Dry::Inflector::Acronyms
Acronyms
-
#human(rule, replacement)
Add a custom humanize rule
-
#humans : Dry::Inflector::Rules
Human rules
-
#irregular(singular, plural)
Add a custom pluralization rule
-
#plural(rule, replacement)
Add a custom pluralization rule
-
#plurals : Dry::Inflector::Rules
Pluralization rules
-
#singular(rule, replacement)
Add a custom singularization rule
-
#singulars : Dry::Inflector::Rules
Singularization rules
- #uncountable(words : Enumerable(String))
-
#uncountable(word)
Add a custom rule for uncountable words
-
#uncountables : Set(String)
Uncountable rules
Constructor Detail
Instantiate a set of inflection rules. It adds the default rules and the optional customizations, passed as a block.
@param blk [Proc] the optional, custom rules
@since 0.1.0 @api private
Instantiate the rules
@return [Dry::Inflector::Inflections] @yieldparam [self]
@since 0.1.0 @api private
Instance Method Detail
Add one or more acronyms
Acronyms affect how basic operations are performed, such as camelize/underscore.
@param words [Array
@since 0.1.2
@example require "dry/inflector"
inflector = Dry::Inflector.new do |inflections| inflections.acronym "HTML" end
inflector.camelize("html") # => "HTML" inflector.underscore("HTMLIsFun") # => "html_is_fun"
Acronyms
@return [Dry::Inflector::Acronyms]
@since 0.1.2 @api private
Add a custom humanize rule
Specifies a humanized form of a string by a regular expression rule or by a string mapping.
When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
When a string is used, the human form should be specified as desired
(example: "The name"
, not "the_name"
)
@param rule [String, Regex] the rule @param replacement [String] the replacement
@since 0.1.0
@example require "dry/inflector"
inflector = Dry::Inflector.new do |inflections| inflections.human(/_cnt$/i, '\1_count') inflections.human("legacy_col_person_name", "Name") end
Human rules
@return [Dry::Inflector::Rules]
@since 0.1.0 @api private
Add a custom pluralization rule
Specifies a new irregular that applies to both pluralization and singularization at the same time.
This can only be used for strings, not regular expressions. You simply pass the irregular in singular and plural form.
@param singular [String] the singular @param plural [String] the plural
@since 0.1.0
@example require "dry/inflector"
inflector = Dry::Inflector.new do |inflections| inflections.singular "octopus", "octopi" end
Add a custom pluralization rule
Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
The replacement should always be a string that may include references to the matched data from the rule.
@param rule [String, Regex] the rule @param replacement [String] the replacement
@since 0.1.0
@example require "dry/inflector"
inflector = Dry::Inflector.new do |inflections| inflections.plural "virus", "viruses" end
Pluralization rules
@return [Dry::Inflector::Rules]
@since 0.1.0 @api private
Add a custom singularization rule
Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
The replacement should always be a string that may include references to the matched data from the rule.
@param rule [String, Regex] the rule @param replacement [String] the replacement
@since 0.1.0
@example require "dry/inflector"
inflector = Dry::Inflector.new do |inflections| inflections.singular "thieves", "thief" end
Singularization rules
@return [Dry::Inflector::Rules]
@since 0.1.0 @api private
Add a custom rule for uncountable words
Uncountable will not be inflected
@param [Enumerable
@since 0.1.0
@example require "dry/inflector"
inflector = Dry::Inflector.new do |inflections| inflections.uncountable "money" inflections.uncountable "money", "information" inflections.uncountable %w(money information rice) end