Class: Mindee::Parsing::V2::Field::FieldConfidence

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/parsing/v2/field/field_confidence.rb

Overview

Confidence level of a field as returned by the V2 API.

Constant Summary collapse

CERTAIN =

Absolute certainty about the field's extraction.

'Certain'
HIGH =

High certainty about the field's extraction.

'High'
MEDIUM =

Medium certainty about the field's extraction.

'Medium'
LOW =

Low certainty about the field's extraction.

'Low'
VALID_VALUES =

List of valid values, as frozen strings.

['Certain', 'High', 'Medium', 'Low'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ FieldConfidence

Returns a new instance of FieldConfidence.

Parameters:

  • value (String)

    The confidence level value.

Raises:

  • (ArgumentError)

    If the value is not a valid confidence level.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mindee/parsing/v2/field/field_confidence.rb', line 26

def initialize(value)
  case value
  when 'Certain' then @value = CERTAIN
  when 'High' then @value = HIGH
  when 'Medium' then @value = MEDIUM
  when 'Low' then @value = LOW
  else
    raise ArgumentError,
          "Invalid confidence level: '#{value}'. Must be one of: #{VALID_VALUES.join(', ')}"
  end

  @value = value
end

Instance Attribute Details

#valueString (readonly)

Returns The confidence level value.

Returns:

  • (String)

    The confidence level value.



10
11
12
# File 'lib/mindee/parsing/v2/field/field_confidence.rb', line 10

def value
  @value
end

Instance Method Details

#<=(other) ⇒ Object Also known as: lteql?

less than or equality of two FieldConfidence instances.

@param other [String, Integer, FieldConfidence] The other confidence to compare.



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/mindee/parsing/v2/field/field_confidence.rb', line 92

def <=(other)
  if other.is_a?(FieldConfidence)
    to_i <= val_to_i(other.value)
  elsif other.is_a?(String)
    to_i <= val_to_i(other)
  elsif other.is_a?(Integer)
    to_i <= other
  else
    raise ArgumentError, "Invalid type: #{other.class}"
  end
end

#==(other) ⇒ Boolean Also known as: eql?

Equality of two FieldConfidence instances.

Parameters:

  • other (String, Integer, FieldConfidence)

    The other confidence to compare.

Returns:

  • (Boolean)

    true if they have the same value.



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mindee/parsing/v2/field/field_confidence.rb', line 64

def ==(other)
  if other.is_a?(FieldConfidence)
    @value == other.value
  elsif other.is_a?(String)
    @value == other
  elsif other.is_a?(Integer)
    to_i == other
  else
    raise ArgumentError, "Invalid type: #{other.class}"
  end
end

#>=(other) ⇒ Object Also known as: gteql?

Greater than or equality of two FieldConfidence instances.

Parameters:

  • other (String, Integer, FieldConfidence)

    The other confidence to compare.



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/mindee/parsing/v2/field/field_confidence.rb', line 78

def >=(other)
  if other.is_a?(FieldConfidence)
    to_i >= val_to_i(other.value)
  elsif other.is_a?(String)
    to_i >= val_to_i(other)
  elsif other.is_a?(Integer)
    to_i >= other
  else
    raise ArgumentError, "Invalid type: #{other.class}"
  end
end

#inspectString

Inspect method for debugging.

Returns:

  • (String)

    Debug representation.



54
55
56
# File 'lib/mindee/parsing/v2/field/field_confidence.rb', line 54

def inspect
  "#<#{self.class.name}:#{@value}>"
end

#to_iInteger

String representation of the confidence level.

Returns:

  • (Integer)

    The confidence level value as an integer: 1 is LOW, 4 is HIGH.



48
49
50
# File 'lib/mindee/parsing/v2/field/field_confidence.rb', line 48

def to_i
  val_to_i(@value)
end

#to_sString

String representation of the confidence level.

Returns:

  • (String)

    The confidence level value.



42
43
44
# File 'lib/mindee/parsing/v2/field/field_confidence.rb', line 42

def to_s
  @value
end