Sha256: 211f58837e7de4e425f696477b9b9b61fbf39e76e03086130915a4558ad806c3

Contents?: true

Size: 899 Bytes

Versions: 7

Compression:

Stored size: 899 Bytes

Contents

module Lotus
  module Validations
    # @since 0.2.2
    # @api private
    class BlankValueChecker
      # @since 0.2.2
      # @api private
      BLANK_STRING_MATCHER = /\A[[:space:]]*\z/.freeze

      def initialize(value)
        @value = value
      end

      # Checks if the value is "blank".
      #
      # @since 0.2.2
      # @api private
      def blank_value?
        _nil_value? || _blank_string? || _empty_value?
      end

      private

      # Checks if the value is `nil`.
      #
      # @since 0.2.2
      # @api private
      def _nil_value?
        @value.nil?
      end

      # @since 0.2.2
      # @api private
      def _blank_string?
        (@value.respond_to?(:match) and @value.match(BLANK_STRING_MATCHER))
      end

      # @since 0.2.2
      # @api private
      def _empty_value?
        (@value.respond_to?(:empty?) and @value.empty?)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lotus-validations-0.3.3 lib/lotus/validations/blank_value_checker.rb
lotus-validations-0.3.2 lib/lotus/validations/blank_value_checker.rb
lotus-validations-0.3.1 lib/lotus/validations/blank_value_checker.rb
lotus-validations-0.3.0 lib/lotus/validations/blank_value_checker.rb
lotus-validations-0.2.4 lib/lotus/validations/blank_value_checker.rb
lotus-validations-0.2.3 lib/lotus/validations/blank_value_checker.rb
lotus-validations-0.2.2 lib/lotus/validations/blank_value_checker.rb