Class: Mindee::Parsing::Custom::ListField

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/parsing/custom/list_field.rb

Overview

Field where actual values are kept in a list (custom docs).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prediction, page_id, reconstructed: false) ⇒ ListField

Returns a new instance of ListField.

Parameters:

  • prediction (Hash)
  • page_id (Integer, nil)
  • reconstructed (Boolean) (defaults to: false)


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/mindee/parsing/custom/list_field.rb', line 49

def initialize(prediction, page_id, reconstructed: false)
  @values = []
  @confidence = prediction['confidence']
  page_id = prediction['page_id'] if page_id.nil? && prediction.include?('page_id')
  @reconstructed = reconstructed

  prediction['values'].each do |field|
    page_id = field['page_id'] if field.include?('page_id')
    @values.push(ListFieldItem.new(field, page_id: page_id))
  end
end

Instance Attribute Details

#confidenceFloat

The confidence score, value will be between 0.0 and 1.0

Returns:

  • (Float)


44
45
46
# File 'lib/mindee/parsing/custom/list_field.rb', line 44

def confidence
  @confidence
end

#reconstructedBoolean (readonly)

true if the field was reconstructed or computed using other fields.

Returns:

  • (Boolean)


41
42
43
# File 'lib/mindee/parsing/custom/list_field.rb', line 41

def reconstructed
  @reconstructed
end

#valuesArray<Mindee::Parsing::Custom::ListFieldItem> (readonly)



38
39
40
# File 'lib/mindee/parsing/custom/list_field.rb', line 38

def values
  @values
end

Instance Method Details

#contents_listArray

Returns:

  • (Array)


62
63
64
# File 'lib/mindee/parsing/custom/list_field.rb', line 62

def contents_list
  @values.map(&:content)
end

#contents_str(separator: ' ') ⇒ String

Returns:

  • (String)


67
68
69
# File 'lib/mindee/parsing/custom/list_field.rb', line 67

def contents_str(separator: ' ')
  @values.map(&:to_s).join(separator)
end

#to_sString

Returns:

  • (String)


72
73
74
# File 'lib/mindee/parsing/custom/list_field.rb', line 72

def to_s
  contents_str(separator: ' ')
end