Sha256: 563a53d1281f932608ea9288b8c6e63c4082caba24bad4a28aeca21cfe151e88

Contents?: true

Size: 592 Bytes

Versions: 7

Compression:

Stored size: 592 Bytes

Contents

module PR
  module Fields
    class BooleanField
      TrueValues  = [1,"1","true",true]
      FalseValues = [0,"0","false",false, ""]

      def initialize value = nil, options = {}
        @value, @options = value, options
      end
      attr_reader :options

      def populate value
        @value = value
      end

      def raw
        convert
      end

      def convert
        if TrueValues.include? @value
          return true
        elsif FalseValues.include? @value
          return false
        else
          @value ? true : false
        end
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pr-1.0.0 lib/pr/fields/boolean_field.rb
pr-0.0.7 lib/pr/fields/boolean_field.rb
pr-0.0.6 lib/pr/fields/boolean_field.rb
pr-0.0.5 lib/pr/fields/boolean_field.rb
pr-0.0.4 lib/pr/fields/boolean_field.rb
pr-0.0.3 lib/pr/fields/boolean_field.rb
pr-0.0.2 lib/pr/fields/boolean_field.rb