Class: KeyVortex::Constraint::Length

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

Overview

Enforces that objects which respond to #length less than the specified limit.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#applies_to?, #to_s

Constructor Details

#initialize(limit) ⇒ Length

Returns a new instance of Length.

Parameters:

  • limit (Integer)

    The maximum allowed value



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

def initialize(limit)
  super()
  @limit = limit
end

Instance Attribute Details

#limitInteger (readonly)

Returns The upper bound allowed when calling #length on a value.

Returns:

  • (Integer)

    The upper bound allowed when calling #length on a value



11
12
13
# File 'lib/key_vortex/constraint/length.rb', line 11

def limit
  @limit
end

Instance Method Details

#accepts?(value) ⇒ Boolean

Returns True if length <= limit.

Parameters:

  • value (Object)

    Must respond to #length

Returns:

  • (Boolean)

    True if length <= limit



32
33
34
# File 'lib/key_vortex/constraint/length.rb', line 32

def accepts?(value)
  value.length <= limit
end

#attributeSymbol

Returns :length.

Returns:

  • (Symbol)

    :length



20
21
22
# File 'lib/key_vortex/constraint/length.rb', line 20

def attribute
  :length
end

#within?(constraint) ⇒ Boolean

Returns True if limit <= constraint.limit.

Parameters:

Returns:

  • (Boolean)

    True if limit <= constraint.limit



26
27
28
# File 'lib/key_vortex/constraint/length.rb', line 26

def within?(constraint)
  super && limit <= constraint.limit
end