Summary
This plugin adds new simple validation to your rails models. It validates that the value of the specified attribute does not exceed specified word count.
SVN Repository
http://validates-word-count.googlecode.com/svn/
Installation
> ruby ./script/plugin install http://validates-word-count.googlecode.com/svn/tags/validates-word-count
Usage
Just drop the following lines to a model you want to add this validation to:
class Article < ActiveRecord::Base validates_word_count :summary, :maximum => 30 validates_word_count :about_author, :minimum => 25 validates_word_count :annotation, :in => 100..150 end
That's it. It will make sure that the :summary value does not exceed 30 words, :annotation value word count is in 100..150 words range, and about_autor has at least 25 words.
It supports regular validation options such as :if, :unless, :allow_nil etc., and works fine in conjunction with 'Validation Scenariios' plugin (http://agilewebdevelopment.com/plugins/validation_scenarios)
It also extends ruby core String class and adds 'words' method to it, so all the following assertions pass:
assert_equal 0, ''.words assert_equal 1, 'Hello'.words assert_equal 2, 'Hello All!'.words