Class: Mindee::V1::Parsing::Universal::UniversalObjectField
- Inherits:
-
Object
- Object
- Mindee::V1::Parsing::Universal::UniversalObjectField
- Defined in:
- lib/mindee/v1/parsing/universal/universal_object_field.rb
Overview
A JSON-like object, with miscellaneous values.
Instance Attribute Summary collapse
-
#all_values ⇒ Hash
readonly
All values.
-
#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 ⇒ String
readonly
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 DX 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.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mindee/v1/parsing/universal/universal_object_field.rb', line 29 def initialize(raw_prediction, page_id = nil) @all_values = {} # : Hash[String | Symbol, 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.
69 70 71 72 |
# File 'lib/mindee/v1/parsing/universal/universal_object_field.rb', line 69 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
#all_values ⇒ Hash (readonly)
All values
23 24 25 |
# File 'lib/mindee/v1/parsing/universal/universal_object_field.rb', line 23 def all_values @all_values end |
#confidence ⇒ Float (readonly)
The confidence score, value will be between 0.0 and 1.0
17 18 19 |
# File 'lib/mindee/v1/parsing/universal/universal_object_field.rb', line 17 def confidence @confidence end |
#page_id ⇒ Integer (readonly)
ID of the page (as given by the API).
14 15 16 |
# File 'lib/mindee/v1/parsing/universal/universal_object_field.rb', line 14 def page_id @page_id end |
#raw_value ⇒ String (readonly)
Value as String
20 21 22 |
# File 'lib/mindee/v1/parsing/universal/universal_object_field.rb', line 20 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 DX 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.
83 84 85 |
# File 'lib/mindee/v1/parsing/universal/universal_object_field.rb', line 83 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.
50 51 52 53 54 55 56 57 58 |
# File 'lib/mindee/v1/parsing/universal/universal_object_field.rb', line 50 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
88 89 90 |
# File 'lib/mindee/v1/parsing/universal/universal_object_field.rb', line 88 def to_s str_level end |