File: boolean_normalizer.rb

package info (click to toggle)
ruby-attribute-normalizer 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 108 kB
  • sloc: ruby: 213; makefile: 7
file content (18 lines) | stat: -rw-r--r-- 429 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Extracted from ActiveRecord::ConnectionAdapters::Column
require 'set'

module AttributeNormalizer
  module Normalizers
    module BooleanNormalizer
      TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].to_set

      def self.normalize(value, options = {})
        if value.is_a?(String) && value.blank?
          nil
        else
          TRUE_VALUES.include?(value)
        end
      end
    end
  end
end