Module: English::Inflect

Defined in:
lib/english_extensions/inflect.rb

Overview

English Nouns Number Inflection.

This module provides english singular <-> plural noun inflections.

Class Method Summary collapse

Class Method Details

.plural(word) ⇒ Object

Convert an English word from singular to plurel.

"boy".plural     #=> boys
"tomato".plural  #=> tomatoes


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/english_extensions/inflect.rb', line 33

def plural(word)
  if result = plural_of[word]
    return result.dup
  end
  #return self.dup if /s$/ =~ self # ???
  result = word.dup
  pluralization_rules.each do |(match, replacement)|
    break if result.gsub!(match, replacement)
  end
  # Mack: cache the result of the translation:
  plural_of[word] = result unless word == result
  return result
end

.singular(word) ⇒ Object

Convert an English word from plurel to singular.

"boys".singular      #=> boy
"tomatoes".singular  #=> tomato


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/english_extensions/inflect.rb', line 15

def singular(word)
  if result = singular_of[word]
    return result.dup
  end
  result = word.dup
  singularization_rules.each do |(match, replacement)|
    break if result.gsub!(match, replacement)
  end
  # Mack: cache the result of the translation:
  singular_of[word] = result unless word == result
  return result
end