Class: Axlsx::RestrictionValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/util/validators.rb

Overview

Validate a value against a specific list of allowed values.

Class Method Summary collapse

Class Method Details

.validate(name, choices, v) ⇒ Boolean

Perform validation

Parameters:

  • name (String)

    The name of what is being validatied. This is included in the error message

  • choices (Array)

    The list of choices to validate against

  • v (Any)

    The value to be validated

Returns:

  • (Boolean)

    true if validation succeeds.

Raises:

  • (ArgumentError)

    Raised if the value provided is not in the list of choices.



12
13
14
15
16
# File 'lib/axlsx/util/validators.rb', line 12

def self.validate(name, choices, v)
  raise ArgumentError, format(ERR_RESTRICTION, v.to_s, name, choices.inspect) unless choices.include?(v)

  true
end