Validates Word Count plugin

Plugin details

Documentation

Install the plugin:
ruby script/plugin install http://validates-word-count.googlecode.com/svn/tags/validates-word-count/

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

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: Guest, 9 months ago