mindee 3.11.0 → 3.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/bin/mindee.rb +7 -1
- data/docs/code_samples/financial_document_v1_async.txt +19 -0
- data/docs/code_samples/us_healthcare_cards_v1_async.txt +19 -0
- data/docs/expense_receipts_v5.md +12 -10
- data/docs/financial_document_v1.md +51 -22
- data/docs/invoices_v4.md +4 -3
- data/docs/us_healthcare_cards_v1.md +204 -0
- data/lib/mindee/image_extraction/common/extracted_image.rb +73 -0
- data/lib/mindee/image_extraction/common/image_extractor.rb +191 -0
- data/lib/mindee/image_extraction/common.rb +3 -0
- data/lib/mindee/image_extraction/multi_receipts_extractor/multi_receipts_extractor.rb +26 -0
- data/lib/mindee/image_extraction/multi_receipts_extractor.rb +3 -0
- data/lib/mindee/image_extraction.rb +4 -0
- data/lib/mindee/input/sources.rb +8 -0
- data/lib/mindee/parsing/standard/company_registration_field.rb +17 -0
- data/lib/mindee/product/financial_document/financial_document_v1_document.rb +3 -1
- data/lib/mindee/product/financial_document/financial_document_v1_line_item.rb +7 -0
- data/lib/mindee/product/financial_document/financial_document_v1_page.rb +1 -1
- data/lib/mindee/product/international_id/international_id_v2_document.rb +1 -1
- data/lib/mindee/product/international_id/international_id_v2_page.rb +1 -1
- data/lib/mindee/product/invoice/invoice_v4_document.rb +3 -1
- data/lib/mindee/product/invoice/invoice_v4_line_item.rb +7 -0
- data/lib/mindee/product/invoice/invoice_v4_page.rb +1 -1
- data/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rb +1 -1
- data/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rb +1 -1
- data/lib/mindee/product/receipt/receipt_v5_document.rb +1 -1
- data/lib/mindee/product/receipt/receipt_v5_page.rb +1 -1
- data/lib/mindee/product/us/healthcare_card/healthcare_card_v1.rb +41 -0
- data/lib/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rb +57 -0
- data/lib/mindee/product/us/healthcare_card/healthcare_card_v1_document.rb +127 -0
- data/lib/mindee/product/us/healthcare_card/healthcare_card_v1_page.rb +34 -0
- data/lib/mindee/product.rb +1 -0
- data/lib/mindee/version.rb +1 -1
- data/mindee.gemspec +1 -0
- metadata +29 -2
@@ -0,0 +1,191 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mini_magick'
|
4
|
+
require 'origami'
|
5
|
+
require 'stringio'
|
6
|
+
require 'tempfile'
|
7
|
+
require_relative '../../input/sources'
|
8
|
+
require_relative 'extracted_image'
|
9
|
+
|
10
|
+
module Mindee
|
11
|
+
# Image Extraction Module.
|
12
|
+
module ImageExtraction
|
13
|
+
def attach_image_as_new_file(input_buffer)
|
14
|
+
# Attaches an image as a new page in a PdfDocument object.
|
15
|
+
#
|
16
|
+
# @param [StringIO] input_buffer Input buffer. Only supports JPEG.
|
17
|
+
# @return [Origami::PDF] A PdfDocument handle.
|
18
|
+
|
19
|
+
magick_image = MiniMagick::Image.read(input_buffer)
|
20
|
+
# NOTE: some jpeg images get rendered as three different versions of themselves per output if the format isn't
|
21
|
+
# converted.
|
22
|
+
magick_image.format('jpg')
|
23
|
+
original_density = magick_image.resolution
|
24
|
+
scale_factor = original_density[0].to_f / 4.166666 # No clue why bit the resolution needs to be reduced for
|
25
|
+
# the pdf otherwise the resulting image shrinks.
|
26
|
+
magick_image.format('pdf', 0, { density: scale_factor.to_s })
|
27
|
+
io_buffer = StringIO.new
|
28
|
+
magick_image.write(io_buffer)
|
29
|
+
Origami::PDF.read(io_buffer)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Extracts multiple images from a given local input source.
|
33
|
+
#
|
34
|
+
# @param [Mindee::Input::Source::LocalInputSource] input_source
|
35
|
+
# @param [Integer] page_id ID of the Page to extract from.
|
36
|
+
# @param [Array<Array<Mindee::Geometry::Point>>, Array<Mindee::Geometry::Quadrangle>] polygons List of coordinates
|
37
|
+
# to extract.
|
38
|
+
# @return [Array<Mindee::ImageExtraction::ExtractedImage>] Extracted Images.
|
39
|
+
def extract_multiple_images_from_source(input_source, page_id, polygons)
|
40
|
+
new_stream = load_doc(input_source, page_id)
|
41
|
+
new_stream.seek(0)
|
42
|
+
|
43
|
+
extract_images_from_polygons(input_source, new_stream, page_id, polygons)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Retrieves a PDF document's page.
|
47
|
+
#
|
48
|
+
# @param [Origami::PDF] pdf_doc Origami PDF handle.
|
49
|
+
# @param [Integer] page_id Page ID.
|
50
|
+
def get_page(pdf_doc, page_id)
|
51
|
+
stream = StringIO.new
|
52
|
+
pdf_doc.save(stream)
|
53
|
+
|
54
|
+
options = {
|
55
|
+
page_indexes: [page_id - 1],
|
56
|
+
}
|
57
|
+
|
58
|
+
Mindee::PDF::PdfProcessor.parse(stream, options)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Extracts images from their positions on a file (as polygons).
|
62
|
+
#
|
63
|
+
# @param [Mindee::Input::Source::LocalInputSource] input_source Local input source.
|
64
|
+
# @param [StringIO] pdf_stream Buffer of the PDF.
|
65
|
+
# @param [Integer] page_id Page ID.
|
66
|
+
# @param [Array<Mindee::Geometry::Point, Mindee::Geometry::Polygon, Mindee::Geometry::Quadrangle>] polygons
|
67
|
+
# @return [Array<Mindee::ImageExtraction::ExtractedImage>] Extracted Images.
|
68
|
+
def extract_images_from_polygons(input_source, pdf_stream, page_id, polygons)
|
69
|
+
extracted_elements = []
|
70
|
+
|
71
|
+
polygons.each_with_index do |polygon, element_id|
|
72
|
+
polygon = normalize_polygon(polygon)
|
73
|
+
page_content = read_page_content(pdf_stream)
|
74
|
+
|
75
|
+
min_max_x = Geometry.get_min_max_x([
|
76
|
+
polygon.top_left,
|
77
|
+
polygon.bottom_right,
|
78
|
+
polygon.top_right,
|
79
|
+
polygon.bottom_left,
|
80
|
+
])
|
81
|
+
min_max_y = Geometry.get_min_max_y([
|
82
|
+
polygon.top_left,
|
83
|
+
polygon.bottom_right,
|
84
|
+
polygon.top_right,
|
85
|
+
polygon.bottom_left,
|
86
|
+
])
|
87
|
+
file_extension = determine_file_extension(input_source)
|
88
|
+
cropped_image = crop_image(page_content, min_max_x, min_max_y)
|
89
|
+
if file_extension == 'pdf'
|
90
|
+
cropped_image.format('jpg')
|
91
|
+
else
|
92
|
+
cropped_image.format(file_extension)
|
93
|
+
end
|
94
|
+
|
95
|
+
buffer = StringIO.new
|
96
|
+
write_image_to_buffer(cropped_image, buffer)
|
97
|
+
file_name = "#{input_source.filename}_page#{page_id}-#{element_id}.#{file_extension}"
|
98
|
+
|
99
|
+
extracted_elements << create_extracted_image(buffer, file_name, page_id, element_id)
|
100
|
+
end
|
101
|
+
|
102
|
+
extracted_elements
|
103
|
+
end
|
104
|
+
|
105
|
+
# Retrieves the bounding box of a polygon.
|
106
|
+
#
|
107
|
+
# @param [Array<Point>, Mindee::Geometry::Polygon] polygon
|
108
|
+
def normalize_polygon(polygon)
|
109
|
+
if polygon.is_a?(Mindee::Geometry::Polygon)
|
110
|
+
Mindee::Geometry.get_bounding_box(polygon)
|
111
|
+
else
|
112
|
+
polygon
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Loads a buffer into a MiniMagick Image.
|
117
|
+
#
|
118
|
+
# @param [StringIO] pdf_stream Buffer containg the PDF
|
119
|
+
# @return [MiniMagick::Image] a valid MiniMagick image handle.
|
120
|
+
def read_page_content(pdf_stream)
|
121
|
+
pdf_stream.rewind
|
122
|
+
MiniMagick::Image.read(pdf_stream)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Crops a MiniMagick Image from a the given bounding box.
|
126
|
+
#
|
127
|
+
# @param [MiniMagick::Image] image Input Image.
|
128
|
+
# @param [Mindee::Geometry::MinMax] min_max_x minimum & maximum values for the x coordinates.
|
129
|
+
# @param [Mindee::Geometry::MinMax] min_max_y minimum & maximum values for the y coordinates.
|
130
|
+
def crop_image(image, min_max_x, min_max_y)
|
131
|
+
width = image[:width].to_i
|
132
|
+
height = image[:height].to_i
|
133
|
+
|
134
|
+
image.format('jpg')
|
135
|
+
new_width = (min_max_x.max - min_max_x.min) * width
|
136
|
+
new_height = (min_max_y.max - min_max_y.min) * height
|
137
|
+
image.crop("#{new_width}x#{new_height}+#{min_max_x.min * width}+#{min_max_y.min * height}")
|
138
|
+
|
139
|
+
image
|
140
|
+
end
|
141
|
+
|
142
|
+
# Writes a MiniMagick::Image to a buffer.
|
143
|
+
#
|
144
|
+
# @param [MiniMagick::Image] image a valid MiniMagick image.
|
145
|
+
# @param [StringIO] buffer
|
146
|
+
def write_image_to_buffer(image, buffer)
|
147
|
+
image.write(buffer)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Retrieves the file extension from the main file to apply it to the extracted images. Note: coerces pdf as jpg.
|
151
|
+
#
|
152
|
+
# @param [Mindee::Input::Source::LocalInputSource] input_source Local input source.
|
153
|
+
# @return [String] A valid file extension.
|
154
|
+
def determine_file_extension(input_source)
|
155
|
+
if input_source.pdf? || input_source.filename.downcase.end_with?('pdf')
|
156
|
+
'jpg'
|
157
|
+
else
|
158
|
+
File.extname(input_source.filename).strip.downcase[1..]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# Generates an ExtractedImage.
|
163
|
+
#
|
164
|
+
# @param [StringIO] buffer Buffer containing the image.
|
165
|
+
# @param [String] file_name Name for the file.
|
166
|
+
# @param [Object] page_id ID of the page the file was generated from.
|
167
|
+
# @param [Object] element_id ID of the element of a given page.
|
168
|
+
def create_extracted_image(buffer, file_name, page_id, element_id)
|
169
|
+
buffer.rewind
|
170
|
+
ExtractedImage.new(
|
171
|
+
Mindee::Input::Source::BytesInputSource.new(buffer.read, file_name),
|
172
|
+
page_id,
|
173
|
+
element_id
|
174
|
+
)
|
175
|
+
end
|
176
|
+
|
177
|
+
# Loads a single_page from an image file or a pdf document.
|
178
|
+
#
|
179
|
+
# @param input_file [LocalInputSource] Local input.
|
180
|
+
# @param [Integer] page_id Page ID.
|
181
|
+
# @return [MiniMagick::Image] A valid PdfDocument handle.
|
182
|
+
def load_doc(input_file, page_id)
|
183
|
+
input_file.io_stream.rewind
|
184
|
+
if input_file.pdf?
|
185
|
+
get_page(Origami::PDF.read(input_file.io_stream), page_id)
|
186
|
+
else
|
187
|
+
input_file.io_stream
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mindee
|
4
|
+
# Image Extraction Module.
|
5
|
+
module ImageExtraction
|
6
|
+
def extract_receipts(input_source, inference)
|
7
|
+
# Extracts individual receipts from multi-receipts documents.
|
8
|
+
#
|
9
|
+
# @param input_source [LocalInputSource] Local Input Source to extract sub-receipts from.
|
10
|
+
# @param inference [Inference] Results of the inference.
|
11
|
+
# @return [Array<ExtractedImage>] Individual extracted receipts as an array of ExtractedMultiReceiptsImage.
|
12
|
+
|
13
|
+
images = []
|
14
|
+
raise 'No possible receipts candidates found for MultiReceipts extraction.' unless inference.prediction.receipts
|
15
|
+
|
16
|
+
(0...input_source.count_pdf_pages).each do |page_id|
|
17
|
+
receipt_positions = inference.pages[page_id].prediction.receipts.map(&:bounding_box)
|
18
|
+
images.concat(
|
19
|
+
extract_multiple_images_from_source(input_source, page_id + 1, receipt_positions)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
images
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/mindee/input/sources.rb
CHANGED
@@ -118,6 +118,14 @@ module Mindee
|
|
118
118
|
@io_stream.close if close
|
119
119
|
['document', data, { filename: Mindee::Input::Source.convert_to_unicode_escape(@filename) }]
|
120
120
|
end
|
121
|
+
|
122
|
+
def count_pdf_pages
|
123
|
+
return 1 unless pdf?
|
124
|
+
|
125
|
+
@io_stream.seek(0)
|
126
|
+
pdf_processor = Mindee::PDF::PdfProcessor.open_pdf(@io_stream)
|
127
|
+
pdf_processor.pages.size
|
128
|
+
end
|
121
129
|
end
|
122
130
|
|
123
131
|
# Load a document from a path.
|
@@ -15,6 +15,23 @@ module Mindee
|
|
15
15
|
super
|
16
16
|
@type = prediction['type']
|
17
17
|
end
|
18
|
+
|
19
|
+
def to_table_line
|
20
|
+
printable = printable_values
|
21
|
+
format('| %<type>-15s | %<value>-20s ', type: printable['type'], value: printable['value'])
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
printable = printable_values
|
26
|
+
format('Type: %<type>s, Value: %<value>s', type: printable['type'], value: printable['value'])
|
27
|
+
end
|
28
|
+
|
29
|
+
def printable_values
|
30
|
+
printable = {}
|
31
|
+
printable['type'] = type
|
32
|
+
printable['value'] = value
|
33
|
+
printable
|
34
|
+
end
|
18
35
|
end
|
19
36
|
end
|
20
37
|
end
|
@@ -6,7 +6,7 @@ require_relative 'financial_document_v1_line_item'
|
|
6
6
|
module Mindee
|
7
7
|
module Product
|
8
8
|
module FinancialDocument
|
9
|
-
# Financial Document API version 1.
|
9
|
+
# Financial Document API version 1.9 document data.
|
10
10
|
class FinancialDocumentV1Document < Mindee::Parsing::Common::Prediction
|
11
11
|
include Mindee::Parsing::Standard
|
12
12
|
# The customer's address used for billing.
|
@@ -206,6 +206,7 @@ module Mindee
|
|
206
206
|
out_str << "+#{char * 12}"
|
207
207
|
out_str << "+#{char * 14}"
|
208
208
|
out_str << "+#{char * 14}"
|
209
|
+
out_str << "+#{char * 17}"
|
209
210
|
out_str << "+#{char * 12}"
|
210
211
|
out_str << '+'
|
211
212
|
out_str
|
@@ -225,6 +226,7 @@ module Mindee
|
|
225
226
|
out_str << ' Tax Amount |'
|
226
227
|
out_str << ' Tax Rate (%) |'
|
227
228
|
out_str << ' Total Amount |'
|
229
|
+
out_str << ' Unit of measure |'
|
228
230
|
out_str << ' Unit Price |'
|
229
231
|
out_str << "\n#{line_items_separator('=')}"
|
230
232
|
out_str << "\n #{line_items}"
|
@@ -26,6 +26,9 @@ module Mindee
|
|
26
26
|
# The item total amount.
|
27
27
|
# @return [Float]
|
28
28
|
attr_reader :total_amount
|
29
|
+
# The item unit of measure.
|
30
|
+
# @return [String]
|
31
|
+
attr_reader :unit_measure
|
29
32
|
# The item unit price.
|
30
33
|
# @return [Float]
|
31
34
|
attr_reader :unit_price
|
@@ -40,6 +43,7 @@ module Mindee
|
|
40
43
|
@tax_amount = prediction['tax_amount']
|
41
44
|
@tax_rate = prediction['tax_rate']
|
42
45
|
@total_amount = prediction['total_amount']
|
46
|
+
@unit_measure = prediction['unit_measure']
|
43
47
|
@unit_price = prediction['unit_price']
|
44
48
|
@page_id = page_id
|
45
49
|
end
|
@@ -53,6 +57,7 @@ module Mindee
|
|
53
57
|
printable[:tax_amount] = @tax_amount.nil? ? '' : Field.float_to_string(@tax_amount)
|
54
58
|
printable[:tax_rate] = @tax_rate.nil? ? '' : Field.float_to_string(@tax_rate)
|
55
59
|
printable[:total_amount] = @total_amount.nil? ? '' : Field.float_to_string(@total_amount)
|
60
|
+
printable[:unit_measure] = format_for_display(@unit_measure, nil)
|
56
61
|
printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price)
|
57
62
|
printable
|
58
63
|
end
|
@@ -67,6 +72,7 @@ module Mindee
|
|
67
72
|
out_str << format('| %- 11s', printable[:tax_amount])
|
68
73
|
out_str << format('| %- 13s', printable[:tax_rate])
|
69
74
|
out_str << format('| %- 13s', printable[:total_amount])
|
75
|
+
out_str << format('| %- 16s', printable[:unit_measure])
|
70
76
|
out_str << format('| %- 11s', printable[:unit_price])
|
71
77
|
out_str << '|'
|
72
78
|
end
|
@@ -81,6 +87,7 @@ module Mindee
|
|
81
87
|
out_str << "\n :Tax Amount: #{printable[:tax_amount]}"
|
82
88
|
out_str << "\n :Tax Rate (%): #{printable[:tax_rate]}"
|
83
89
|
out_str << "\n :Total Amount: #{printable[:total_amount]}"
|
90
|
+
out_str << "\n :Unit of measure: #{printable[:unit_measure]}"
|
84
91
|
out_str << "\n :Unit Price: #{printable[:unit_price]}"
|
85
92
|
out_str
|
86
93
|
end
|
@@ -6,7 +6,7 @@ require_relative 'financial_document_v1_document'
|
|
6
6
|
module Mindee
|
7
7
|
module Product
|
8
8
|
module FinancialDocument
|
9
|
-
# Financial Document API version 1.
|
9
|
+
# Financial Document API version 1.9 page data.
|
10
10
|
class FinancialDocumentV1Page < Mindee::Parsing::Common::Page
|
11
11
|
# @param prediction [Hash]
|
12
12
|
def initialize(prediction)
|
@@ -5,7 +5,7 @@ require_relative '../../parsing'
|
|
5
5
|
module Mindee
|
6
6
|
module Product
|
7
7
|
module InternationalId
|
8
|
-
# International ID API version 2.
|
8
|
+
# International ID API version 2.1 document data.
|
9
9
|
class InternationalIdV2Document < Mindee::Parsing::Common::Prediction
|
10
10
|
include Mindee::Parsing::Standard
|
11
11
|
# The physical address of the document holder.
|
@@ -6,7 +6,7 @@ require_relative 'international_id_v2_document'
|
|
6
6
|
module Mindee
|
7
7
|
module Product
|
8
8
|
module InternationalId
|
9
|
-
# International ID API version 2.
|
9
|
+
# International ID API version 2.1 page data.
|
10
10
|
class InternationalIdV2Page < Mindee::Parsing::Common::Page
|
11
11
|
# @param prediction [Hash]
|
12
12
|
def initialize(prediction)
|
@@ -6,7 +6,7 @@ require_relative 'invoice_v4_line_item'
|
|
6
6
|
module Mindee
|
7
7
|
module Product
|
8
8
|
module Invoice
|
9
|
-
# Invoice API version 4.
|
9
|
+
# Invoice API version 4.7 document data.
|
10
10
|
class InvoiceV4Document < Mindee::Parsing::Common::Prediction
|
11
11
|
include Mindee::Parsing::Standard
|
12
12
|
# The customer's address used for billing.
|
@@ -176,6 +176,7 @@ module Mindee
|
|
176
176
|
out_str << "+#{char * 12}"
|
177
177
|
out_str << "+#{char * 14}"
|
178
178
|
out_str << "+#{char * 14}"
|
179
|
+
out_str << "+#{char * 17}"
|
179
180
|
out_str << "+#{char * 12}"
|
180
181
|
out_str << '+'
|
181
182
|
out_str
|
@@ -195,6 +196,7 @@ module Mindee
|
|
195
196
|
out_str << ' Tax Amount |'
|
196
197
|
out_str << ' Tax Rate (%) |'
|
197
198
|
out_str << ' Total Amount |'
|
199
|
+
out_str << ' Unit of measure |'
|
198
200
|
out_str << ' Unit Price |'
|
199
201
|
out_str << "\n#{line_items_separator('=')}"
|
200
202
|
out_str << "\n #{line_items}"
|
@@ -26,6 +26,9 @@ module Mindee
|
|
26
26
|
# The item total amount.
|
27
27
|
# @return [Float]
|
28
28
|
attr_reader :total_amount
|
29
|
+
# The item unit of measure.
|
30
|
+
# @return [String]
|
31
|
+
attr_reader :unit_measure
|
29
32
|
# The item unit price.
|
30
33
|
# @return [Float]
|
31
34
|
attr_reader :unit_price
|
@@ -40,6 +43,7 @@ module Mindee
|
|
40
43
|
@tax_amount = prediction['tax_amount']
|
41
44
|
@tax_rate = prediction['tax_rate']
|
42
45
|
@total_amount = prediction['total_amount']
|
46
|
+
@unit_measure = prediction['unit_measure']
|
43
47
|
@unit_price = prediction['unit_price']
|
44
48
|
@page_id = page_id
|
45
49
|
end
|
@@ -53,6 +57,7 @@ module Mindee
|
|
53
57
|
printable[:tax_amount] = @tax_amount.nil? ? '' : Field.float_to_string(@tax_amount)
|
54
58
|
printable[:tax_rate] = @tax_rate.nil? ? '' : Field.float_to_string(@tax_rate)
|
55
59
|
printable[:total_amount] = @total_amount.nil? ? '' : Field.float_to_string(@total_amount)
|
60
|
+
printable[:unit_measure] = format_for_display(@unit_measure, nil)
|
56
61
|
printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price)
|
57
62
|
printable
|
58
63
|
end
|
@@ -67,6 +72,7 @@ module Mindee
|
|
67
72
|
out_str << format('| %- 11s', printable[:tax_amount])
|
68
73
|
out_str << format('| %- 13s', printable[:tax_rate])
|
69
74
|
out_str << format('| %- 13s', printable[:total_amount])
|
75
|
+
out_str << format('| %- 16s', printable[:unit_measure])
|
70
76
|
out_str << format('| %- 11s', printable[:unit_price])
|
71
77
|
out_str << '|'
|
72
78
|
end
|
@@ -81,6 +87,7 @@ module Mindee
|
|
81
87
|
out_str << "\n :Tax Amount: #{printable[:tax_amount]}"
|
82
88
|
out_str << "\n :Tax Rate (%): #{printable[:tax_rate]}"
|
83
89
|
out_str << "\n :Total Amount: #{printable[:total_amount]}"
|
90
|
+
out_str << "\n :Unit of measure: #{printable[:unit_measure]}"
|
84
91
|
out_str << "\n :Unit Price: #{printable[:unit_price]}"
|
85
92
|
out_str
|
86
93
|
end
|
@@ -6,7 +6,7 @@ require_relative 'invoice_v4_document'
|
|
6
6
|
module Mindee
|
7
7
|
module Product
|
8
8
|
module Invoice
|
9
|
-
# Invoice API version 4.
|
9
|
+
# Invoice API version 4.7 page data.
|
10
10
|
class InvoiceV4Page < Mindee::Parsing::Common::Page
|
11
11
|
# @param prediction [Hash]
|
12
12
|
def initialize(prediction)
|
@@ -5,7 +5,7 @@ require_relative '../../parsing'
|
|
5
5
|
module Mindee
|
6
6
|
module Product
|
7
7
|
module MultiReceiptsDetector
|
8
|
-
# Multi Receipts Detector API version 1.
|
8
|
+
# Multi Receipts Detector API version 1.1 document data.
|
9
9
|
class MultiReceiptsDetectorV1Document < Mindee::Parsing::Common::Prediction
|
10
10
|
include Mindee::Parsing::Standard
|
11
11
|
# Positions of the receipts on the document.
|
@@ -6,7 +6,7 @@ require_relative 'multi_receipts_detector_v1_document'
|
|
6
6
|
module Mindee
|
7
7
|
module Product
|
8
8
|
module MultiReceiptsDetector
|
9
|
-
# Multi Receipts Detector API version 1.
|
9
|
+
# Multi Receipts Detector API version 1.1 page data.
|
10
10
|
class MultiReceiptsDetectorV1Page < Mindee::Parsing::Common::Page
|
11
11
|
# @param prediction [Hash]
|
12
12
|
def initialize(prediction)
|
@@ -6,7 +6,7 @@ require_relative 'receipt_v5_line_item'
|
|
6
6
|
module Mindee
|
7
7
|
module Product
|
8
8
|
module Receipt
|
9
|
-
# Receipt API version 5.
|
9
|
+
# Receipt API version 5.3 document data.
|
10
10
|
class ReceiptV5Document < Mindee::Parsing::Common::Prediction
|
11
11
|
include Mindee::Parsing::Standard
|
12
12
|
# The purchase category among predefined classes.
|
@@ -6,7 +6,7 @@ require_relative 'receipt_v5_document'
|
|
6
6
|
module Mindee
|
7
7
|
module Product
|
8
8
|
module Receipt
|
9
|
-
# Receipt API version 5.
|
9
|
+
# Receipt API version 5.3 page data.
|
10
10
|
class ReceiptV5Page < Mindee::Parsing::Common::Page
|
11
11
|
# @param prediction [Hash]
|
12
12
|
def initialize(prediction)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
require_relative 'healthcare_card_v1_document'
|
5
|
+
require_relative 'healthcare_card_v1_page'
|
6
|
+
|
7
|
+
module Mindee
|
8
|
+
module Product
|
9
|
+
module US
|
10
|
+
# Healthcare Card module.
|
11
|
+
module HealthcareCard
|
12
|
+
# Healthcare Card API version 1 inference prediction.
|
13
|
+
class HealthcareCardV1 < Mindee::Parsing::Common::Inference
|
14
|
+
@endpoint_name = 'us_healthcare_cards'
|
15
|
+
@endpoint_version = '1'
|
16
|
+
|
17
|
+
# @param prediction [Hash]
|
18
|
+
def initialize(prediction)
|
19
|
+
super
|
20
|
+
@prediction = HealthcareCardV1Document.new(prediction['prediction'], nil)
|
21
|
+
@pages = []
|
22
|
+
prediction['pages'].each do |page|
|
23
|
+
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
|
24
|
+
@pages.push(HealthcareCardV1Page.new(page))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
# Name of the endpoint for this product.
|
31
|
+
# @return [String]
|
32
|
+
attr_reader :endpoint_name
|
33
|
+
# Version for this product.
|
34
|
+
# @return [String]
|
35
|
+
attr_reader :endpoint_version
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Product
|
7
|
+
module US
|
8
|
+
module HealthcareCard
|
9
|
+
# Is a fixed amount for a covered service.
|
10
|
+
class HealthcareCardV1Copay < Mindee::Parsing::Standard::FeatureField
|
11
|
+
include Mindee::Parsing::Standard
|
12
|
+
# The price of service.
|
13
|
+
# @return [Float]
|
14
|
+
attr_reader :service_fees
|
15
|
+
# The name of service of the copay.
|
16
|
+
# @return [String]
|
17
|
+
attr_reader :service_name
|
18
|
+
|
19
|
+
# @param prediction [Hash]
|
20
|
+
# @param page_id [Integer, nil]
|
21
|
+
def initialize(prediction, page_id)
|
22
|
+
super(prediction, page_id)
|
23
|
+
@service_fees = prediction['service_fees']
|
24
|
+
@service_name = prediction['service_name']
|
25
|
+
@page_id = page_id
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [Hash]
|
29
|
+
def printable_values
|
30
|
+
printable = {}
|
31
|
+
printable[:service_fees] = @service_fees.nil? ? '' : Field.float_to_string(@service_fees)
|
32
|
+
printable[:service_name] = format_for_display(@service_name, nil)
|
33
|
+
printable
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [String]
|
37
|
+
def to_table_line
|
38
|
+
printable = printable_values
|
39
|
+
out_str = String.new
|
40
|
+
out_str << format('| %- 13s', printable[:service_fees])
|
41
|
+
out_str << format('| %- 13s', printable[:service_name])
|
42
|
+
out_str << '|'
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [String]
|
46
|
+
def to_s
|
47
|
+
printable = printable_values
|
48
|
+
out_str = String.new
|
49
|
+
out_str << "\n :Service Fees: #{printable[:service_fees]}"
|
50
|
+
out_str << "\n :Service Name: #{printable[:service_name]}"
|
51
|
+
out_str
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|