class Thumbtack::Types::MD5

Handles validation of MD5 types as the values supported by Pinboard

@api private

Constants

CHARACTERS

The valid characters in an MD5 value

LENGTH

The length of an MD5 value

Public Class Methods

validate(value) click to toggle source

Validate a string is a valid MD5 parameter

@param [String] value

the MD5 to validate

@return [self]

@raise [Types::ValidationError]

if the value is not a 32 character hexadecimal MD5 hash
# File lib/thumbtack/types/md5.rb, line 23
def self.validate(value)
  unless valid_md5?(value)
    raise ValidationError,
          "#{value} must be a 32 character hexadecimal MD5 hash"
  end
  self
end

Private Class Methods

valid_md5?(value) click to toggle source

If true, the value is a valid MD5 string

@param [String] value

the MD5 to validate

@return [Boolean]

@api private

# File lib/thumbtack/types/md5.rb, line 39
def self.valid_md5?(value)
  value.length == LENGTH &&
    value.each_char.all? { |char| CHARACTERS.include?(char) }
end