Class: Rosette::Core::Validators::EncodingValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/rosette/core/validators/encoding_validator.rb

Overview

Validates an encoding.

Examples:

v = EncodingValidator.new
v.valid?(Encoding::UTF_8, nil, nil) # => true
v.valid?('foo', nil, nil)  # => false
v.messages  # => ["Encoding 'foo' was not recognized."]

Instance Attribute Summary

Attributes inherited from Validator

#options

Instance Method Summary collapse

Methods inherited from Validator

#initialize, #messages

Constructor Details

This class inherits a constructor from Rosette::Core::Validators::Validator

Instance Method Details

#valid?(encoding, repo_name, configuration) ⇒ Boolean

Returns true if the encoding is valid, false otherwise.

Parameters:

  • encoding (String, Encoding)

    The encoding to validate.

  • repo_name (String)

    (not used)

  • configuration (Configurator)

    (not used)

Returns:

  • (Boolean)

21
22
23
24
25
26
27
# File 'lib/rosette/core/validators/encoding_validator.rb', line 21

def valid?(encoding, repo_name, configuration)
  Encoding.find(encoding)
  true
rescue ArgumentError
  messages << "Encoding '#{encoding}' was not recognized."
  false
end