Sha256: 08c338aa5db3e6b7db1f832c86403007916cbe1e642ba14a56690619a0fffe6e

Contents?: true

Size: 611 Bytes

Versions: 4

Compression:

Stored size: 611 Bytes

Contents

module Formulario
  class Field
    class Boolean < Field
      def self.for(raw_value)
        if raw_value.is_a?(Field)
          raw_value
        else
          build(raw_value)
        end
      end

      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
formulario-0.1.2 lib/formulario/fields/boolean.rb
formulario-0.1.1b lib/formulario/fields/boolean.rb
formulario-0.1.1 lib/formulario/fields/boolean.rb
formulario-0.1.0 lib/formulario/fields/boolean.rb