Class: Treat::Workers::Inflectors::Declensors::English

Inherits:
Object
  • Object
show all
Defined in:
lib/treat/workers/inflectors/declensors/english.rb

Overview

Inflection using the inflect module copied from the unmaintained ‘english’ ruby gem.

License: MIT Website: english.rubyforge.org

Constant Summary collapse

POS =

Part of speech that can be declensed.

['noun', 'adjective', 'determiner']

Class Method Summary collapse

Class Method Details

.declense(entity, options) ⇒ Object

Retrieve the declensions (singular, plural) of an english word using a class lifted from the ‘english’ ruby gem.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/treat/workers/inflectors/declensors/english.rb', line 16

def self.declense(entity, options)
  cat = entity.check_has(:category)
  return unless POS.include?(cat)
  unless options[:count]
    raise Treat::Exception, 'Must supply ' +
    'option count ("singular" or "plural").'
  end
  string = entity.to_s
  if options[:count].to_s == 'plural'
    Inflect.plural(string)
  elsif options[:count].to_s == 'singular'
    Inflect.singular(string)
  end
end