Class: Hanami::Utils::Inflector::IrregularRules Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/utils/inflector.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Rules for irregular plurals

Since:

  • 0.6.0

Instance Method Summary collapse

Constructor Details

#initialize(rules) ⇒ IrregularRules

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of IrregularRules.

Since:

  • 0.6.0



17
18
19
# File 'lib/hanami/utils/inflector.rb', line 17

def initialize(rules)
  @rules = rules
end

Instance Method Details

#===(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.6.0



29
30
31
32
# File 'lib/hanami/utils/inflector.rb', line 29

def ===(other)
  key = other.downcase
  @rules.key?(key) || @rules.value?(key)
end

#add(key, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.6.0



23
24
25
# File 'lib/hanami/utils/inflector.rb', line 23

def add(key, value)
  @rules[key.downcase] = value.downcase
end

#apply(string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.6.0



36
37
38
39
40
41
# File 'lib/hanami/utils/inflector.rb', line 36

def apply(string)
  key    = string.downcase
  result = @rules[key] || @rules.rassoc(key).last

  string[0] + result[1..-1]
end