Class: Mindee::Parsing::V2::Field::FieldConfidence
- Inherits:
-
Object
- Object
- Mindee::Parsing::V2::Field::FieldConfidence
- 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
-
#value ⇒ String
readonly
The confidence level value.
Instance Method Summary collapse
-
#<=(other) ⇒ Object
(also: #lteql?)
less than or equality of two FieldConfidence instances.
-
#==(other) ⇒ Boolean
(also: #eql?)
Equality of two FieldConfidence instances.
-
#>=(other) ⇒ Object
(also: #gteql?)
Greater than or equality of two FieldConfidence instances.
-
#initialize(value) ⇒ FieldConfidence
constructor
A new instance of FieldConfidence.
-
#inspect ⇒ String
Inspect method for debugging.
-
#to_i ⇒ Integer
String representation of the confidence level.
-
#to_s ⇒ String
String representation of the confidence level.
Constructor Details
#initialize(value) ⇒ FieldConfidence
Returns a new instance of FieldConfidence.
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
#value ⇒ String (readonly)
Returns 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.
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.
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 |
#inspect ⇒ String
Inspect method for debugging.
54 55 56 |
# File 'lib/mindee/parsing/v2/field/field_confidence.rb', line 54 def inspect "#<#{self.class.name}:#{@value}>" end |
#to_i ⇒ Integer
String representation of the confidence level.
48 49 50 |
# File 'lib/mindee/parsing/v2/field/field_confidence.rb', line 48 def to_i val_to_i(@value) end |
#to_s ⇒ String
String representation of the confidence level.
42 43 44 |
# File 'lib/mindee/parsing/v2/field/field_confidence.rb', line 42 def to_s @value end |