<commit_before>{<img src="https://secure.travis-ci.org/rubiety/nilify_blanks.png?branch=master" alt="Build Status" />}[http://travis-ci.org/rubiety/nilify_blanks]
{<img src="https://gemnasium.com/rubiety/nilify_blanks.png" alt="Dependency Status" />}[https://gemnasium.com/rubiety/nilify_blanks]
{<img src="https://codeclimate.com/github/rubiety/nilify_blanks.png" />}[https://codeclimate.com/github/rubiety/nilify_blanks]

== Nilify Blanks

In Rails when saving a model from a form and values are not provided by the user, an empty string is recorded to the database instead of a NULL as many would prefer (mixing blanks and NULLs can become confusing).  This plugin allows you to specify a list of attributes (or exceptions from all the attributes) that will be converted to nil if they are blank before a model is saved.  

Only attributes responding to empty? with a value of true will be converted to nil.  Therefore, this does not work with integer fields with the value of 0, for example.  Usage is best shown through examples:

== Requirements

Rails 3.0 or later is required (ActiveRecord implementation is very different in Rails 2 and not easy to support both).

Due to issues maintaining backwards compatibility, as of v1.2.0 this gem requires ruby 1.9.3 or higher. 
If you are still using 1.8.7 or 1.9.2, please use the v1.1.0 release.

== Install

Include the gem using bundler in your Gemfile:

  gem "nilify_blanks"

== Basic Usage

  # Checks and converts all content fields in the model
  class Post < ActiveRecord::Base
    nilify_blanks
  end

  # Checks and converts only text fields in the model
  class Post < ActiveRecord::Base
    nilify_blanks :types => [:text]<commit_msg>change .empty? in readme to .blank? since this is what the gem does. E.G .blank? on a string filled with spaces will return true but .empty? will return false.<commit_after>{<img src="https://secure.travis-ci.org/rubiety/nilify_blanks.png?branch=master" alt="Build Status" />}[http://travis-ci.org/rubiety/nilify_blanks]
{<img src="https://gemnasium.com/rubiety/nilify_blanks.png" alt="Dependency Status" />}[https://gemnasium.com/rubiety/nilify_blanks]
{<img src="https://codeclimate.com/github/rubiety/nilify_blanks.png" />}[https://codeclimate.com/github/rubiety/nilify_blanks]

== Nilify Blanks

In Rails when saving a model from a form and values are not provided by the user, an empty string is recorded to the database instead of a NULL as many would prefer (mixing blanks and NULLs can become confusing).  This plugin allows you to specify a list of attributes (or exceptions from all the attributes) that will be converted to nil if they are blank before a model is saved.  

Only attributes responding to blank? with a value of true will be converted to nil.  Therefore, this does not work with integer fields with the value of 0, for example.  Usage is best shown through examples:

== Requirements

Rails 3.0 or later is required (ActiveRecord implementation is very different in Rails 2 and not easy to support both).

Due to issues maintaining backwards compatibility, as of v1.2.0 this gem requires ruby 1.9.3 or higher. 
If you are still using 1.8.7 or 1.9.2, please use the v1.1.0 release.

== Install

Include the gem using bundler in your Gemfile:

  gem "nilify_blanks"

== Basic Usage

  # Checks and converts all content fields in the model
  class Post < ActiveRecord::Base
    nilify_blanks
  end

  # Checks and converts only text fields in the model
  class Post < ActiveRecord::Base
    nilify_blanks :types => [:text]
{'fraction_non_alphanumeric': 0.08267494356659143, 'fraction_numerical': 0.01072234762979684, 'mean_word_length': 4.259643916913946, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1911077', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1037, 'n_words': 455}