Class: Mindee::Parsing::V2::Field::BaseField
- Inherits:
-
Object
- Object
- Mindee::Parsing::V2::Field::BaseField
- Defined in:
- lib/mindee/parsing/v2/field/base_field.rb
Overview
Base class for V2 fields.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#confidence ⇒ FieldConfidence?
readonly
Confidence score for the field.
-
#indent_level ⇒ Integer
readonly
Level of indentation for rst display.
-
#locations ⇒ Array<FieldLocation>
readonly
List of locations the field was found at.
Class Method Summary collapse
-
.create_field(raw_prediction, indent_level = 0) ⇒ BaseField
Factory method to create appropriate field types.
Instance Method Summary collapse
-
#initialize(raw_prediction, indent_level = 0) ⇒ BaseField
constructor
A new instance of BaseField.
Constructor Details
#initialize(raw_prediction, indent_level = 0) ⇒ BaseField
Returns a new instance of BaseField.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mindee/parsing/v2/field/base_field.rb', line 21 def initialize(raw_prediction, indent_level = 0) @indent_level = indent_level confidence = raw_prediction['confidence'] @confidence = FieldConfidence.new(confidence) unless confidence.nil? || confidence.empty? locations = raw_prediction['locations'] @locations = if locations.nil? || locations.empty? [] else locations.map do |location| FieldLocation.new(location) end end end |
Instance Attribute Details
#confidence ⇒ FieldConfidence? (readonly)
Returns Confidence score for the field.
14 15 16 |
# File 'lib/mindee/parsing/v2/field/base_field.rb', line 14 def confidence @confidence end |
#indent_level ⇒ Integer (readonly)
Returns Level of indentation for rst display.
11 12 13 |
# File 'lib/mindee/parsing/v2/field/base_field.rb', line 11 def indent_level @indent_level end |
#locations ⇒ Array<FieldLocation> (readonly)
Returns List of locations the field was found at.
17 18 19 |
# File 'lib/mindee/parsing/v2/field/base_field.rb', line 17 def locations @locations end |
Class Method Details
.create_field(raw_prediction, indent_level = 0) ⇒ BaseField
Factory method to create appropriate field types.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mindee/parsing/v2/field/base_field.rb', line 41 def self.create_field(raw_prediction, indent_level = 0) if raw_prediction.key?('items') require_relative 'list_field' return ListField.new(raw_prediction, indent_level) end if raw_prediction.key?('fields') require_relative 'object_field' return ObjectField.new(raw_prediction, indent_level) end if raw_prediction.key?('value') require_relative 'simple_field' return SimpleField.new(raw_prediction, indent_level) end raise Errors::MindeeError, "Unrecognized field format in #{raw_prediction.to_json}" end |