Sha256: cd12b476c4a284cf147c8cd23f8860fa678d1f3a634589d081d5d7d1118945b8

Contents?: true

Size: 945 Bytes

Versions: 6

Compression:

Stored size: 945 Bytes

Contents

module Koine
  module Attributes
    module Adapter
      class Boolean < Base
        DEFAULT_TRUE_VALUES = [1, '1', true, 'true'].freeze
        DEFAULT_FALSE_VALUES = [0, '0', false, 'false'].freeze

        def initialize(
          true_values: DEFAULT_TRUE_VALUES.dup,
          false_values: DEFAULT_FALSE_VALUES.dup
        )
          @true_values = true_values
          @false_values = false_values
        end

        def append_true_value(value)
          true_values << value
          self
        end

        def append_false_value(value)
          false_values << value
          self
        end

        private

        attr_reader :true_values
        attr_reader :false_values

        def coerce_not_nil(value)
          return true if true_values.include?(value)
          return false if false_values.include?(value)
          raise ArgumentError, "Invalid argument '#{value}'"
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
koine-attributes-1.1.0 lib/koine/attributes/adapter/boolean.rb
koine-attributes-1.0.0 lib/koine/attributes/adapter/boolean.rb
koine-attributes-0.4.0 lib/koine/attributes/adapter/boolean.rb
koine-attributes-0.3.2 lib/koine/attributes/adapter/boolean.rb
koine-attributes-0.3.1 lib/koine/attributes/adapter/boolean.rb
koine-attributes-0.3.0 lib/koine/attributes/adapter/boolean.rb