Module | String::Inflections |
In: |
lib/sequel/extensions/inflector.rb
lib/sequel/model/deprecated_inflector.rb |
This module acts as a singleton returned/yielded by String.inflections, which is used to override or specify additional inflection rules. Examples:
String.inflections do |inflect| inflect.plural /^(ox)$/i, '\1\2en' inflect.singular /^(ox)en/i, '\1' inflect.irregular 'octopus', 'octopi' inflect.uncountable "equipment" end
New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may already have been loaded.
plurals | [R] | |
plurals | [R] | |
singulars | [R] | |
singulars | [R] | |
uncountables | [R] | |
uncountables | [R] |
Clears the loaded inflections within a given scope (default is :all). Give the scope as a symbol of the inflection type, the options are: :plurals, :singulars, :uncountables
Examples:
clear :all clear :plurals
# File lib/sequel/extensions/inflector.rb, line 34 34: def self.clear(scope = :all) 35: Sequel::Inflections.clear(scope) 36: case scope 37: when :all 38: @plurals, @singulars, @uncountables = [], [], [] 39: else 40: instance_variable_set("@#{scope}", []) 41: end 42: end
Clears the loaded inflections within a given scope (default is :all). Give the scope as a symbol of the inflection type, the options are: :plurals, :singulars, :uncountables
Examples:
clear :all clear :plurals
# File lib/sequel/model/deprecated_inflector.rb, line 34 34: def self.clear(scope = :all) 35: Sequel::Deprecation.deprecate('String::Inflections.clear', 'require "sequel/extensions/inflector" first') 36: Sequel::Inflections.clear(scope) 37: case scope 38: when :all 39: @plurals, @singulars, @uncountables = [], [], [] 40: else 41: instance_variable_set("@#{scope}", []) 42: end 43: end
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.
Examples:
irregular 'octopus', 'octopi' irregular 'person', 'people'
# File lib/sequel/model/deprecated_inflector.rb, line 51 51: def self.irregular(singular, plural) 52: Sequel::Deprecation.deprecate('String::Inflections.irregular', 'require "sequel/extensions/inflector" first') 53: Sequel::Inflections.irregular(singular, plural) 54: plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1]) 55: singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1]) 56: end
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.
Examples:
irregular 'octopus', 'octopi' irregular 'person', 'people'
# File lib/sequel/extensions/inflector.rb, line 50 50: def self.irregular(singular, plural) 51: Sequel::Inflections.irregular(singular, plural) 52: plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1]) 53: singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1]) 54: end
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.
Example:
plural(/(x|ch|ss|sh)$/i, '\1es')
# File lib/sequel/extensions/inflector.rb, line 61 61: def self.plural(rule, replacement) 62: Sequel::Inflections.plural(rule, replacement) 63: @plurals.insert(0, [rule, replacement]) 64: end
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.
Example:
plural(/(x|ch|ss|sh)$/i, '\1es')
# File lib/sequel/model/deprecated_inflector.rb, line 63 63: def self.plural(rule, replacement) 64: Sequel::Deprecation.deprecate('String::Inflections.plural', 'require "sequel/extensions/inflector" first') 65: Sequel::Inflections.plural(rule, replacement) 66: @plurals.insert(0, [rule, replacement]) 67: end
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.
Example:
singular(/([^aeiouy]|qu)ies$/i, '\1y')
# File lib/sequel/extensions/inflector.rb, line 71 71: def self.singular(rule, replacement) 72: Sequel::Inflections.singular(rule, replacement) 73: @singulars.insert(0, [rule, replacement]) 74: end
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.
Example:
singular(/([^aeiouy]|qu)ies$/i, '\1y')
# File lib/sequel/model/deprecated_inflector.rb, line 74 74: def self.singular(rule, replacement) 75: Sequel::Deprecation.deprecate('String::Inflections.singular', 'require "sequel/extensions/inflector" first') 76: Sequel::Inflections.singular(rule, replacement) 77: @singulars.insert(0, [rule, replacement]) 78: end
Add uncountable words that shouldn‘t be attempted inflected.
Examples:
uncountable "money" uncountable "money", "information" uncountable %w( money information rice )
# File lib/sequel/extensions/inflector.rb, line 82 82: def self.uncountable(*words) 83: Sequel::Inflections.uncountable(*words) 84: (@uncountables << words).flatten! 85: end
Add uncountable words that shouldn‘t be attempted inflected.
Examples:
uncountable "money" uncountable "money", "information" uncountable %w( money information rice )
# File lib/sequel/model/deprecated_inflector.rb, line 86 86: def self.uncountable(*words) 87: Sequel::Deprecation.deprecate('String::Inflections.uncountable', 'require "sequel/extensions/inflector" first') 88: Sequel::Inflections.uncountable(*words) 89: (@uncountables << words).flatten! 90: end