Sha256: c9b6f63a6a745c0ebcc524b9120b6b7f2c9b76bca4ff1b45606ae7995a0ec848

Contents?: true

Size: 911 Bytes

Versions: 1

Compression:

Stored size: 911 Bytes

Contents

# encoding: UTF-8

module Rosette
  module Core
    module Validators

      # Validates an encoding.
      #
      # @example
      #   v = EncodingValidator.new
      #   v.valid?(Encoding::UTF_8, nil, nil) # => true
      #   v.valid?('foo', nil, nil)  # => false
      #   v.messages  # => ["Encoding 'foo' was not recognized."]
      class EncodingValidator < Validator
        # Returns true if the encoding is valid, false otherwise.
        #
        # @param [String, Encoding] encoding The encoding to validate.
        # @param [String] repo_name (not used)
        # @param [Configurator] configuration (not used)
        # @return [Boolean]
        def valid?(encoding, repo_name, configuration)
          Encoding.find(encoding)
          true
        rescue ArgumentError
          messages << "Encoding '#{encoding}' was not recognized."
          false
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rosette-core-1.0.1 lib/rosette/core/validators/encoding_validator.rb