module DocumentHydrator::Inflector

Public Class Methods

inflections() { |instance| ... } click to toggle source

Yields a singleton instance of Inflector::Inflections so you can specify additional inflector rules.

Example:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.uncountable "rails"
end
# File lib/document_hydrator/inflector/inflections.rb, line 61
def self.inflections
  if block_given?
    yield Inflections.instance
  else
    Inflections.instance
  end
end
pluralize(word) click to toggle source

Returns the plural form of the word in the string.

Examples:

"post".pluralize             # => "posts"
"octopus".pluralize          # => "octopi"
"sheep".pluralize            # => "sheep"
"words".pluralize            # => "words"
"CamelOctopus".pluralize     # => "CamelOctopi"
# File lib/document_hydrator/inflector/inflections.rb, line 77
def self.pluralize(word)
  result = word.to_s.dup

  if word.empty? || inflections.uncountables.include?(result.downcase)
    result
  else
    inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
    result
  end
end