Sha256: 906db17fd8702680ca372f677b5f22eec025cd0aee2e21d57cdc504510c10315

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/agent_lib/interface'

module Contrast
  module AgentLib
    # This class will hold resulst received form AgentLib structs.
    class EvalResult
      # Name of the Protect rule analyzed.
      # @return [String]
      attr_accessor :rule_id
      # Type of the input.
      # @return [String]
      attr_accessor :input_type
      # Score of the input after AgentLib
      # Analysis
      #
      # @return score [Float]
      attr_accessor :score

      # Init a new EvalResult, and translate results to usable for
      # reporting values.
      #
      # @param hsh [Hash, nil] return from AgentLib populated struct.
      def initialize hsh
        return unless hsh&.cs__is_a?(Hash)

        @rule_id = Contrast::AGENT_LIB.rule_set.key(hsh[:rule_id])
        @input_type = Contrast::AGENT_LIB.input_set.key(hsh[:input_type])
        @score = hsh[:score]
      end

      # Used in specs.
      def to_controlled_hash
        {
            rule_id: rule_id,
            input_type: input_type,
            score: score
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contrast-agent-6.11.0 lib/contrast/agent_lib/return_types/eval_result.rb
contrast-agent-6.10.0 lib/contrast/agent_lib/return_types/eval_result.rb