Class: KeyVortex::Constraint::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/key_vortex/constraint/base.rb

Overview

Base class all other constraints inherit from. Does not define all of the properties necessary for a constraint, and so is inappropriate to be used directly.

Direct Known Subclasses

Length, Maximum, Minimum, Regexp

Instance Method Summary collapse

Instance Method Details

#applies_to?(constraint) ⇒ Boolean

Comparing constraints is only valid when compared to other instances of the same constraint. This helps other parts of the system determine if this is true.

Parameters:

Returns:

  • (Boolean)


14
15
16
# File 'lib/key_vortex/constraint/base.rb', line 14

def applies_to?(constraint)
  attribute == constraint.attribute
end

#to_sString

A text description of the constraint. Assumes subclasses define the methods attribute and limit.

Returns:

  • (String)


29
30
31
# File 'lib/key_vortex/constraint/base.rb', line 29

def to_s
  "#{attribute}: #{limit}"
end

#within?(constraint) ⇒ Boolean

The individual constraint is responsible for making the ultimate determination of if it is within another constraint. What’s common to all of them, though, is that they must be the same class.

Returns:

  • (Boolean)


22
23
24
# File 'lib/key_vortex/constraint/base.rb', line 22

def within?(constraint)
  constraint.instance_of?(self.class)
end