Sha256: 4cdc5629ebcad4e7f542dd01a76fefdab48af8ab9869b7a607f4a5e17a4dbf69

Contents?: true

Size: 857 Bytes

Versions: 14

Compression:

Stored size: 857 Bytes

Contents

module Rasti
  class Form
    module Types
      class Boolean
        class << self

          include Castable

          TRUE_FORMAT  = /^t(rue)?$/i
          FALSE_FORMAT = /^f(alse)?$/i
        
          private

          def valid?(value)
            boolean?(value) || valid_string?(value)
          end

          def transform(value)
            boolean?(value) ? value : true_string?(value)
          end

          def boolean?(value)
            value == true || value == false
          end

          def valid_string?(value)
            value.is_a?(::String) && (true_string?(value) || false_string?(value))
          end

          def true_string?(value)
            !!value.match(TRUE_FORMAT)
          end

          def false_string?(value)
            !!value.match(FALSE_FORMAT)
          end

        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rasti-form-3.1.2 lib/rasti/form/types/boolean.rb
rasti-form-3.1.1 lib/rasti/form/types/boolean.rb
rasti-form-3.1.0 lib/rasti/form/types/boolean.rb
rasti-form-3.0.0 lib/rasti/form/types/boolean.rb
rasti-form-2.2.0 lib/rasti/form/types/boolean.rb
rasti-form-2.1.0 lib/rasti/form/types/boolean.rb
rasti-form-2.0.0 lib/rasti/form/types/boolean.rb
rasti-form-1.1.1 lib/rasti/form/types/boolean.rb
rasti-form-1.1.0 lib/rasti/form/types/boolean.rb
rasti-form-1.0.3 lib/rasti/form/types/boolean.rb
rasti-form-1.0.2 lib/rasti/form/types/boolean.rb
rasti-form-1.0.1 lib/rasti/form/types/boolean.rb
rasti-form-1.0.0 lib/rasti/form/types/boolean.rb
rasti-form-0.1.0 lib/rasti/form/types/boolean.rb