Sha256: cd533b84cd5ea217e2faf4dd557db1d433c67eb2d54cd256fef29d0498b9151d

Contents?: true

Size: 517 Bytes

Versions: 9

Compression:

Stored size: 517 Bytes

Contents

module Formulario
  class Field
    class Boolean < Field
      private

      def self.build(raw_value)
        case get_value(raw_value)
        when true, 'true', 't', '1'
          new true
        when false, 'false', 'f', '0', ''
          new false
        else
          ExceptionalValue.new(raw_value, reasons: ['needs to be boolean'])
        end
      end

      def self.get_value(raw_value)
        raw_value.to_s.downcase
      end

      def self.default
        new(false)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
formulario-0.1.12 lib/formulario/fields/boolean.rb
formulario-0.1.11 lib/formulario/fields/boolean.rb
formulario-0.1.10 lib/formulario/fields/boolean.rb
formulario-0.1.9 lib/formulario/fields/boolean.rb
formulario-0.1.8 lib/formulario/fields/boolean.rb
formulario-0.1.6 lib/formulario/fields/boolean.rb
formulario-0.1.5 lib/formulario/fields/boolean.rb
formulario-0.1.4 lib/formulario/fields/boolean.rb
formulario-0.1.3 lib/formulario/fields/boolean.rb