Sha256: cb52d4e43621d3485798fb4beefbcd243ecb1647efc840e0435be3e3b8b9d55d

Contents?: true

Size: 939 Bytes

Versions: 9

Compression:

Stored size: 939 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 coerce(value)
          return true if true_values.include?(value)
          return false if false_values.include?(value)
          raise ArgumentError, "Invalid argument '#{value}'"
        end

        def append_true_value(value)
          true_values << value
          self
        end

        def append_false_value(value)
          false_values << value
          self
        end

        protected

        attr_reader :true_values
        attr_reader :false_values
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
koine-attributes-0.2.3 lib/koine/attributes/adapter/boolean.rb
koine-attributes-0.2.2 lib/koine/attributes/adapter/boolean.rb
koine-attributes-0.2.1 lib/koine/attributes/adapter/boolean.rb
koine-attributes-0.2.0 lib/koine/attributes/adapter/boolean.rb
koine-attributes-0.1.4 lib/koine/attributes/adapter/boolean.rb
koine-attributes-0.1.3 lib/koine/attributes/adapter/boolean.rb
koine-attributes-0.1.2 lib/koine/attributes/adapter/boolean.rb
koine-attributes-0.1.1 lib/koine/attributes/adapter/boolean.rb
koine-attributes-0.1.0 lib/koine/attributes/adapter/boolean.rb