Module: Hanami::Utils::Inflector

Includes:
ClassAttribute
Defined in:
gems/gems/hanami-utils-1.3.3/lib/hanami/utils/inflector.rb,
gems/gems/hanami-utils-1.3.8/lib/hanami/utils/inflector.rb

Overview

String inflector

Since:

  • 0.4.1

Class Method Summary collapse

Class Method Details

.exception(singular, plural) ⇒ Object

Adds a custom inflection exception

Examples:

require 'hanami/utils/inflector'

Hanami::Utils::Inflector.inflections do
  exception 'alga', 'algae'
end

Parameters:

See Also:

Since:

  • 0.6.0

def self.exception(singular, plural)
  add_to_inflecto(singular, plural)
  singulars.add(plural, singular)
  plurals.add(singular, plural)
end

.inflections(&blk) ⇒ Object

Block for custom inflection rules.

Examples:

require 'hanami/utils/inflector'

Hanami::Utils::Inflector.inflections do
  exception   'analysis', 'analyses'
  exception   'alga',     'algae'
  uncountable 'music', 'butter'
end

Parameters:

  • blk (Proc)

    custom inflections

See Also:

Since:

  • 0.6.0

def self.inflections(&blk)
  class_eval(&blk)
end

.uncountable(*words) ⇒ Object

Adds an uncountable word

Examples:

require 'hanami/utils/inflector'

Hanami::Utils::Inflector.inflections do
  uncountable 'music', 'art'
end

Parameters:

See Also:

Since:

  • 0.6.0

def self.uncountable(*words)
  Array(words).each do |word|
    exception(word, word)
  end
end