Class: Axlsx::RangeValidator

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

Overview

Validate that the value provided is between a specific range Note that no data conversions will be done for you! Comparisons will be made using < and > or <= and <= when the inclusive parameter is true

Class Method Summary collapse

Class Method Details

.validate(name, min, max, value, inclusive = true) ⇒ Object

Parameters:

  • name (String)

    The name of what is being validated

  • min (Any)

    The minimum allowed value

  • max (Any)

    The maximum allowed value

  • value (Any)

    The value to be validated

  • inclusive (Boolean) (defaults to: true)

    Flag indicating if the comparison should be inclusive.

Raises:

  • (ArgumentError)

26
27
28
29
30
31
32
33
# File 'lib/axlsx/util/validators.rb', line 26

def self.validate(name, min, max, value, inclusive = true)
  passes = if inclusive
             min <= value && value <= max
           else
             min < value && value < max
           end
  raise ArgumentError, (ERR_RANGE % [value.inspect, min.to_s, max.to_s, inclusive]) unless passes
end