lib/dry/inflector/inflections.rb in dry-inflector-0.2.0 vs lib/dry/inflector/inflections.rb in dry-inflector-0.2.1
- old
+ new
@@ -85,12 +85,14 @@
# 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.
#
+ # The replacement should always be a string that may include
+ # references to the matched data from the rule.
+ #
# @param rule [String, Regexp] the rule
# @param replacement [String] the replacement
#
# @since 0.1.0
#
@@ -106,12 +108,14 @@
# 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.
#
+ # The replacement should always be a string that may include
+ # references to the matched data from the rule.
+ #
# @param rule [String, Regexp] the rule
# @param replacement [String] the replacement
#
# @since 0.1.0
#
@@ -125,11 +129,13 @@
rule(rule, replacement, singulars)
end
# Add a custom pluralization rule
#
- # Specifies a new irregular that applies to both pluralization and singularization at the same time.
+ # 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
@@ -192,14 +198,19 @@
words.each { |word| @acronyms.add(word.downcase, word) }
end
# 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"`)
+ # 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, Regexp] the rule
# @param replacement [String] the replacement
#
# @since 0.1.0
#
@@ -225,10 +236,10 @@
#
# @since 0.1.0
# @api private
def add_irregular(rule, replacement, target)
head, *tail = rule.chars.to_a
- rule(/(#{head})#{tail.join}\z/i, '\1' + replacement[1..-1], target)
+ rule(/(#{head})#{tail.join}\z/i, "\\1#{replacement[1..]}", target)
end
# Add a new rule
#
# @param rule [String, Regexp] the rule