Class: Lotus::Utils::Inflector::IrregularRules Private

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/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



16
17
18
# File 'lib/lotus/utils/inflector.rb', line 16

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



28
29
30
31
# File 'lib/lotus/utils/inflector.rb', line 28

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



22
23
24
# File 'lib/lotus/utils/inflector.rb', line 22

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



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

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

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