Class: Inspector::Constraint::Violation

Inherits:
Object
  • Object
show all
Defined in:
lib/inspector/constraint/violation.rb,
lib/inspector/constraint/violation/list.rb

Defined Under Namespace

Classes: List

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(constraint) ⇒ Violation

Returns a new instance of Violation.



8
9
10
# File 'lib/inspector/constraint/violation.rb', line 8

def initialize(constraint)
  @constraint = constraint
end

Instance Attribute Details

#constraintObject (readonly)

Returns the value of attribute constraint.



6
7
8
# File 'lib/inspector/constraint/violation.rb', line 6

def constraint
  @constraint
end

Instance Method Details

#inspectObject



26
27
28
29
30
31
# File 'lib/inspector/constraint/violation.rb', line 26

def inspect
  "#<violated %{type} constraint %{constraint}>" % {
    :type       => @constraint.positive? ? 'positive' : 'negative',
    :constraint => @constraint.inspect
  }
end

#negative?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/inspector/constraint/violation.rb', line 16

def negative?
  !@constraint.positive?
end

#positive?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/inspector/constraint/violation.rb', line 12

def positive?
  @constraint.positive?
end

#to_sObject



20
21
22
23
24
# File 'lib/inspector/constraint/violation.rb', line 20

def to_s
  expectation = @constraint.positive? ? 'should' : 'should_not'

  "#{expectation}.#{@constraint}"
end