Sha256: 2f1fb0a5275570d5d562b81a0e43d6d4eb9ea0cfdfe6f13b42f0f6f2cbcdd5fa

Contents?: true

Size: 775 Bytes

Versions: 10

Compression:

Stored size: 775 Bytes

Contents

module OpenActive
  module Validators
    class StringValidator < BaseValidator
      # Coerce given value to the type the validator is validating against.
      # PLEASE NOTE: no checks are performed on the given value.
      # It is therefore recommended to call the "run" method first before this.
      #
      # @param value [mixed] The value to coerce.
      # @return [mixed] The same value.
      def coerce(value)
        value.to_str
      end

      # Run validation on the given value.
      #
      # @param value [mixed] The value to validate.
      # @return [Boolean] Whether validation passes or not.
      def run(value)
        return true if value.is_a?(String)
        return true if value.respond_to?(:to_str)

        false
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
openactive-0.5.0 lib/openactive/validators/string_validator.rb
openactive-0.4.0 lib/openactive/validators/string_validator.rb
openactive-0.3.0 lib/openactive/validators/string_validator.rb
openactive-0.2.2 lib/openactive/validators/string_validator.rb
openactive-0.2.1 lib/openactive/validators/string_validator.rb
openactive-0.2.0 lib/openactive/validators/string_validator.rb
openactive-0.1.2 lib/openactive/validators/string_validator.rb
openactive-0.1.1 lib/openactive/validators/string_validator.rb
openactive-0.1.0 lib/openactive/validators/string_validator.rb
openactive-0.1.0.rc1 lib/openactive/validators/string_validator.rb