class Boolminot::Helpers::RangeBoundsValidator

Attributes

bounds[R]

Public Class Methods

new(bounds) click to toggle source
# File lib/boolminot/helpers/range_bounds_validator.rb, line 6
def initialize(bounds)
  @bounds = bounds
end

Public Instance Methods

valid?() click to toggle source
# File lib/boolminot/helpers/range_bounds_validator.rb, line 10
def valid?
  good_keys    = bounds.keys.all? { |key| valid_keys.include?(key) }
  any_bound    = !(lower_bounds + upper_bounds).empty?
  well_defined = [lower_bounds, upper_bounds].all? { |bounds| bounds.size <= 1 }

  good_keys && any_bound && well_defined
end

Private Instance Methods

lower_bounds() click to toggle source
# File lib/boolminot/helpers/range_bounds_validator.rb, line 24
def lower_bounds
  [bounds[:gt], bounds[:gte]].compact
end
upper_bounds() click to toggle source
# File lib/boolminot/helpers/range_bounds_validator.rb, line 28
def upper_bounds
  [bounds[:lt], bounds[:lte]].compact
end
valid_keys() click to toggle source
# File lib/boolminot/helpers/range_bounds_validator.rb, line 20
def valid_keys
  %i[gt gte lt lte]
end