Class: Mindee::Parsing::Universal::UniversalObjectField
- Inherits:
-
Object
- Object
- Mindee::Parsing::Universal::UniversalObjectField
- Defined in:
- lib/mindee/parsing/universal/universal_object_field.rb
Overview
A JSON-like object, with miscellaneous values.
Instance Attribute Summary collapse
-
#confidence ⇒ Float
readonly
The confidence score, value will be between 0.0 and 1.0.
-
#page_id ⇒ Integer
readonly
ID of the page (as given by the API).
-
#raw_value ⇒ Hash<Symbol | String, untyped>?
Value as String.
Instance Method Summary collapse
-
#initialize(raw_prediction, page_id = nil) ⇒ UniversalObjectField
constructor
ID of the page the object was found on.
-
#method_missing(method_name, *_args) ⇒ Object
Necessary overload of the method_missing method to allow for direct access to dynamic attributes without changing the user usage too much.
-
#respond_to_missing?(method_name, include_private = false) ⇒ bool
Necessary overload of the respond_to_missing? method to allow for direct access to dynamic attributes without changing the user usage too much.
-
#str_level(level = 0) ⇒ Object
String representation that takes into account the level of indentation.
-
#to_s ⇒ Object
String representation.
Constructor Details
#initialize(raw_prediction, page_id = nil) ⇒ UniversalObjectField
ID of the page the object was found on. Confidence with which the value was assessed. Raw unprocessed value, as it was sent by the server.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mindee/parsing/universal/universal_object_field.rb', line 25 def initialize(raw_prediction, page_id = nil) @all_values = {} # : Hash[Symbol | String, untyped] item_page_id = nil raw_prediction.each do |name, value| case name when 'page_id' item_page_id = value when 'polygon', 'rectangle', 'quadrangle', 'bounding_box' handle_position_field(name, value, item_page_id) when 'confidence' @confidence = value when 'raw_value' @raw_value = value else handle_default_field(name, value) end @page_id = page_id || item_page_id end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *_args) ⇒ Object
Necessary overload of the method_missing method to allow for direct access to dynamic attributes without changing the user usage too much. Returns the corresponding attribute when asked.
Otherwise, raises a NoMethodError.
65 66 67 68 |
# File 'lib/mindee/parsing/universal/universal_object_field.rb', line 65 def method_missing(method_name, *_args) super unless @all_values.key?(method_name.to_s) @all_values[method_name.to_s] end |
Instance Attribute Details
#confidence ⇒ Float (readonly)
The confidence score, value will be between 0.0 and 1.0
16 17 18 |
# File 'lib/mindee/parsing/universal/universal_object_field.rb', line 16 def confidence @confidence end |
#page_id ⇒ Integer (readonly)
ID of the page (as given by the API).
13 14 15 |
# File 'lib/mindee/parsing/universal/universal_object_field.rb', line 13 def page_id @page_id end |
#raw_value ⇒ Hash<Symbol | String, untyped>?
Value as String
19 20 21 |
# File 'lib/mindee/parsing/universal/universal_object_field.rb', line 19 def raw_value @raw_value end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ bool
Necessary overload of the respond_to_missing? method to allow for direct access to dynamic attributes without changing the user usage too much. Returns true if the method name exists as a key in @all_values, indicating that the object can respond to the method. Otherwise, calls super to fallback to the default behavior.
79 80 81 |
# File 'lib/mindee/parsing/universal/universal_object_field.rb', line 79 def respond_to_missing?(method_name, include_private = false) @all_values.key?(method_name.to_s) || super end |
#str_level(level = 0) ⇒ Object
String representation that takes into account the level of indentation.
46 47 48 49 50 51 52 53 54 |
# File 'lib/mindee/parsing/universal/universal_object_field.rb', line 46 def str_level(level = 0) indent = " #{' ' * level}" out_str = '' @all_values.each do |attr, value| str_value = value.nil? ? '' : value.to_s out_str += "\n#{indent}:#{attr}: #{str_value}".rstrip end "\n#{indent}#{out_str.strip}" end |
#to_s ⇒ Object
String representation
84 85 86 |
# File 'lib/mindee/parsing/universal/universal_object_field.rb', line 84 def to_s str_level end |