Haris Krajina
Haris Krajina

Reputation: 15296

Ruby gem for resolving pluralization in English

This is strange question in sense that I don't think there is answer for it but here it goes.

I am looking for gem which would allow me to get root word from pluralized word.

categories => category
people     => person
apples     => apple

Trick is I need it in ruby and not in ROR so solution should be independent from ActiveRecord which probably has this mechanism built in. Thanks. There is also paper on this subject that I found http://www.csse.monash.edu.au/~damian/papers/HTML/Plurals.html/ in case somebody is interested in building the gem :)

Upvotes: 3

Views: 757

Answers (3)

DGM
DGM

Reputation: 26979

You could always install just the active_support gem, and require just the inflector, that way you don't load all of rails. Many parts of rails can be used independently.

$ irb
1.9.3-p194 :001 > require 'active_support/inflector'
=> true 
1.9.3-p194 :002 > ActiveSupport::Inflector.singularize('inflections')
=> "inflection" 

Upvotes: 0

cjhveal
cjhveal

Reputation: 5791

You can require just the inflections from ActiveSupport, leaving out the rest of rails, like this:

require 'active_support/core_ext/string/inflections'

If that doesn't work for you, check out the inflections gem.

Upvotes: 0

Bitterzoet
Bitterzoet

Reputation: 2792

This behaviour is defined in ActiveSupport, which you can include on its own without having to require Rails completely.

>> require 'rubygems'
=> true
>> require 'active_support/core_ext/string/inflections'
=> true
>> "categories".singularize
=> "category"

Upvotes: 3

Related Questions