lib/dumb_quotes/ar_extend.rb
def dumb_quotes!(options = nil)
      before_validation do |record|
        attributes = DumbQuotes::ArExtend.narrow(record.attributes, options)
        attributes.each do |attr, value|
          if value.respond_to?(:gsub)
            # single quotes
            value = value.gsub("\xE2\x80\x98","'") # U+2018
            value = value.gsub("\xE2\x80\x99","'") # U+2019
            value = value.gsub("\xCA\xBC","'")     # U+02BC

            #  double quotes
            value = value.gsub("\xE2\x80\x9C",'"') # U+201C
            value = value.gsub("\xE2\x80\x9D",'"') # U+201D
            value = value.gsub("\xCB\xAE",'"')     # U+02EE

            record[attr] = value
          end
        end
      end
    end
# Strips whitespace from model fields and converts blank values to nil.
Strips whitespace from model fields and converts blank values to nil.
Strips whitespace from model fields and converts blank values to nil .
def dumb_quotes!(options = nil)
      before_validation do |record|
        attributes = DumbQuotes::ArExtend.narrow(record.attributes, options)
        attributes.each do |attr, value|
          if value.respond_to?(:gsub)
            value = value.gsub("\xE2\x80\x98","'") 
            value = value.gsub("\xE2\x80\x99","'") 
            value = value.gsub("\xCA\xBC","'")     
            value = value.gsub("\xE2\x80\x9C",'"') 
            value = value.gsub("\xE2\x80\x9D",'"') 
            value = value.gsub("\xCB\xAE",'"')     
            record[attr] = value
          end
        end
      end
    end
def dumb_quotes! ( options = nil ) before_validation do | record | attributes = DumbQuotes :: ArExtend . narrow ( record . attributes , options ) attributes . each do | attr , value | if value . respond_to? ( :gsub ) value = value . gsub ( "\xE2\x80\x98" , "'" ) value = value . gsub ( "\xE2\x80\x99" , "'" ) value = value . gsub ( "\xCA\xBC" , "'" ) value = value . gsub ( "\xE2\x80\x9C" , '"' ) value = value . gsub ( "\xE2\x80\x9D" , '"' ) value = value . gsub ( "\xCB\xAE" , '"' ) record [ attr ] = value end end end end
Strips whitespace from model fields and converts blank values to nil.
Strips whitespace from model fields and converts blank values to nil .
# single quotes # U+2018 # U+2019 # U+02BC #  double quotes # U+201C # U+201D # U+02EE
options