class Xcodeproj::ActiveSupport::Inflector::Inflections
already have been loaded.
pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may
New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the
end
inflect.uncountable “equipment”
inflect.irregular ‘octopus’, ‘octopi’
inflect.singular /^(ox)en/i, ‘1’
inflect.plural /^(ox)$/i, ‘12en’
ActiveSupport::Inflector.inflections do |inflect|
inflection rules. Examples:
A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
def clear(scope = :all)
clear :all
Examples:
:singulars, :uncountables, :humans.
Give the scope as a symbol of the inflection type, the options are: :plurals,
Clears the loaded inflections within a given scope (default is :all).
def clear(scope = :all) case scope when :all @plurals, @singulars, @uncountables = [], [], [] else instance_variable_set "@#{scope}", [] end end
def human(rule, replacement)
human /_cnt$/i, '\1_count'
Examples:
When a string is used, the human form should be specified as desired (example: 'The name', not 'the_name')
When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
Specifies a humanized form of a string by a regular expression rule or by a string mapping.
def human(rule, replacement) @humans.insert(0, [rule, replacement]) end
def initialize
def initialize @plurals, @singulars, @uncountables, @humans = [], [], [], [] end
def irregular(singular, plural)
irregular 'octopus', 'octopi'
Examples:
for strings, not regular expressions. You simply pass the irregular in singular and plural form.
Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
def irregular(singular, plural) @uncountables.delete(singular) @uncountables.delete(plural) if singular[0,1].upcase == plural[0,1].upcase plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1]) singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1]) else plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..-1]) plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..-1]) singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1]) singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1]) end end
def plural(rule, replacement)
Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
def plural(rule, replacement) @uncountables.delete(rule) if rule.is_a?(String) @uncountables.delete(replacement) @plurals.insert(0, [rule, replacement]) end
def singular(rule, replacement)
Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
def singular(rule, replacement) @uncountables.delete(rule) if rule.is_a?(String) @uncountables.delete(replacement) @singulars.insert(0, [rule, replacement]) end
def uncountable(*words)
uncountable "money", "information"
uncountable "money"
Examples:
Add uncountable words that shouldn't be attempted inflected.
def uncountable(*words) (@uncountables << words).flatten! end