Class: Ibex::Verify::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/verify/result.rb,
sig/ibex/verify/result.rbs

Overview

Immutable independent-verification report.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(algorithm:, strict:, checks:, violations:, bounds:) ⇒ Result

Returns a new instance of Result.

RBS:

  • (algorithm: String, strict: bool, checks: Array[String], violations: Array[Violation], bounds: Hash[Symbol, Integer]) -> void

Parameters:

  • algorithm: (String)
  • strict: (Boolean)
  • checks: (Array[String])
  • violations: (Array[Violation])
  • bounds: (Hash[Symbol, Integer])


40
41
42
43
44
45
46
47
# File 'lib/ibex/verify/result.rb', line 40

def initialize(algorithm:, strict:, checks:, violations:, bounds:)
  @algorithm = algorithm.freeze
  @strict = strict
  @checks = checks.dup.freeze
  @violations = violations.dup.freeze
  @bounds = bounds.dup.freeze
  freeze
end

Instance Attribute Details

#algorithmString (readonly)

RBS:

  • type report_value = String | Integer | bool | Array[String] | Hash[Symbol, Integer]
      | Array[Hash[Symbol, String]]

Returns:

  • (String)


32
33
34
# File 'lib/ibex/verify/result.rb', line 32

def algorithm
  @algorithm
end

#boundsHash[Symbol, Integer] (readonly)

Signature:

  • Hash[Symbol, Integer]

Returns:

  • (Hash[Symbol, Integer])


36
37
38
# File 'lib/ibex/verify/result.rb', line 36

def bounds
  @bounds
end

#checksArray[String] (readonly)

Signature:

  • Array[String]

Returns:

  • (Array[String])


34
35
36
# File 'lib/ibex/verify/result.rb', line 34

def checks
  @checks
end

#strictBoolean (readonly)

Signature:

  • bool

Returns:

  • (Boolean)


33
34
35
# File 'lib/ibex/verify/result.rb', line 33

def strict
  @strict
end

#violationsArray[Violation] (readonly)

Signature:

  • Array[Violation]

Returns:



35
36
37
# File 'lib/ibex/verify/result.rb', line 35

def violations
  @violations
end

Instance Method Details

#to_hHash[Symbol, report_value]

RBS:

  • () -> Hash[Symbol, report_value]

Returns:

  • (Hash[Symbol, report_value])


53
54
55
56
57
58
59
60
# File 'lib/ibex/verify/result.rb', line 53

def to_h
  {
    ibex_report: "verify", schema_version: 1, algorithm: @algorithm,
    strict: @strict, checks: @checks, bounds: @bounds,
    result: valid? ? "valid" : "invalid",
    violations: @violations.map(&:to_h)
  }.freeze
end

#valid?Boolean

RBS:

  • () -> bool

Returns:

  • (Boolean)


50
# File 'lib/ibex/verify/result.rb', line 50

def valid? = @violations.empty?