Class: Treat::Workers::Inflectors::Declensors::Linguistics
- Inherits:
-
Object
- Object
- Treat::Workers::Inflectors::Declensors::Linguistics
- Defined in:
- lib/treat/workers/inflectors/declensors/linguistics.rb
Overview
Inflection using the the ‘linguistics’ gem (will attempt to load the Linguistics module corresponding to the language of the entity.
Website: deveiate.org/projects/Linguistics/
Constant Summary collapse
- POS =
Part of speech that can be declensed.
['noun', 'adjective', 'determiner']
Class Method Summary collapse
-
.declense(entity, options = {}) ⇒ Object
Retrieve a declension of a word using the ‘linguistics’ gem.
Class Method Details
.declense(entity, options = {}) ⇒ Object
Retrieve a declension of a word using the ‘linguistics’ gem.
Options:
-
(Identifier) :count => :singular, :plural
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/treat/workers/inflectors/declensors/linguistics.rb', line 16 def self.declense(entity, = {}) cat = entity.get(:category) return if cat && !POS.include?(cat) unless [:count] raise Treat::Exception, 'Must supply ' + ':count option ("singular" or "plural").' end unless [:count].to_s == 'plural' raise Treat::Exception, "Ruby Linguistics does not support " + "singularization of words." end lang = entity.language code = Treat::Loaders::Linguistics.load(lang) obj = entity.to_s.send(code) if cat = entity.get(:category) method = "plural_#{cat}" obj.send(method) else; obj.plural; end end |