Module: ActiveSupport::Inflector

Defined in:
lib/inflectious/inflector.rb

Defined Under Namespace

Classes: Inflections

Instance Method Summary collapse

Instance Method Details

#adjectivize(word) ⇒ Object



18
19
20
# File 'lib/inflectious/inflector.rb', line 18

def adjectivize(word)
  word.match(/y$/) ? word : stem(word) + 'y'
end

#doerize(word) ⇒ Object



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

def doerize(word)
  stem(word) + 'er'
end

#gerundize(word) ⇒ Object



26
27
28
# File 'lib/inflectious/inflector.rb', line 26

def gerundize(word)
  stem(word) + 'ing'
end

#participlize(word) ⇒ Object



30
31
32
# File 'lib/inflectious/inflector.rb', line 30

def participlize(word)
  stem(word) + 'ed'
end

#stem(word) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/inflectious/inflector.rb', line 42

def stem(word)
  result = word.to_s.dup
  if word.empty?
    result
  else
    inflections.stems.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
    result
  end
end

#superlativize(word, options = {}) ⇒ Object



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

def superlativize(word, options = {})
  if options[:adjective]
    stem(word) + 'est'
  else
    word.gsub(/y$/, "i") + 'est'
  end
end