mindee 3.4.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +4 -0
- data/bin/mindee.rb +39 -15
- data/docs/bank_statement_fr_v1.md +175 -0
- data/docs/carte_grise_v1.md +4 -4
- data/docs/code_samples/bank_statement_fr_v1_async.txt +19 -0
- data/docs/code_samples/default.txt +19 -19
- data/docs/code_samples/default_async.txt +25 -0
- data/docs/code_samples/eu_driver_license_v1.txt +19 -0
- data/docs/code_samples/international_id_v1_async.txt +19 -0
- data/docs/code_samples/international_id_v2_async.txt +19 -0
- data/docs/eu_driver_license_v1.md +223 -0
- data/docs/financial_document_v1.md +48 -40
- data/docs/generated_v1.md +90 -0
- data/docs/invoices_v4.md +4 -1
- data/docs/proof_of_address_v1.md +4 -4
- data/docs/us_driver_license_v1.md +2 -2
- data/lib/mindee/client.rb +5 -3
- data/lib/mindee/http/endpoint.rb +13 -12
- data/lib/mindee/input/sources.rb +28 -5
- data/lib/mindee/parsing/common/inference.rb +3 -1
- data/lib/mindee/parsing/generated/generated_list_field.rb +58 -0
- data/lib/mindee/parsing/generated/generated_object_field.rb +109 -0
- data/lib/mindee/parsing/generated.rb +4 -0
- data/lib/mindee/parsing.rb +1 -0
- data/lib/mindee/product/barcode_reader/barcode_reader_v1.rb +3 -1
- data/lib/mindee/product/cropper/cropper_v1.rb +3 -1
- data/lib/mindee/product/eu/driver_license/driver_license_v1.rb +41 -0
- data/lib/mindee/product/eu/driver_license/driver_license_v1_document.rb +88 -0
- data/lib/mindee/product/eu/driver_license/driver_license_v1_page.rb +53 -0
- data/lib/mindee/product/eu/license_plate/license_plate_v1.rb +3 -1
- data/lib/mindee/product/financial_document/financial_document_v1.rb +3 -1
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1.rb +3 -1
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2.rb +3 -1
- data/lib/mindee/product/fr/bank_statement/bank_statement_v1.rb +41 -0
- data/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb +130 -0
- data/lib/mindee/product/fr/bank_statement/bank_statement_v1_page.rb +34 -0
- data/lib/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rb +64 -0
- data/lib/mindee/product/fr/carte_grise/carte_grise_v1.rb +3 -1
- data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1.rb +3 -1
- data/lib/mindee/product/fr/id_card/id_card_v1.rb +3 -1
- data/lib/mindee/product/fr/id_card/id_card_v2.rb +3 -1
- data/lib/mindee/product/generated/generated_v1.rb +38 -0
- data/lib/mindee/product/generated/generated_v1_document.rb +35 -0
- data/lib/mindee/product/generated/generated_v1_page.rb +51 -0
- data/lib/mindee/product/generated/generated_v1_prediction.rb +114 -0
- data/lib/mindee/product/international_id/international_id_v1.rb +39 -0
- data/lib/mindee/product/international_id/international_id_v1_document.rb +109 -0
- data/lib/mindee/product/international_id/international_id_v1_page.rb +32 -0
- data/lib/mindee/product/international_id/international_id_v2.rb +39 -0
- data/lib/mindee/product/international_id/international_id_v2_document.rb +119 -0
- data/lib/mindee/product/international_id/international_id_v2_page.rb +32 -0
- data/lib/mindee/product/invoice/invoice_v4.rb +3 -1
- data/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rb +3 -1
- data/lib/mindee/product/passport/passport_v1.rb +3 -1
- data/lib/mindee/product/proof_of_address/proof_of_address_v1.rb +3 -1
- data/lib/mindee/product/receipt/receipt_v5.rb +3 -1
- data/lib/mindee/product/us/bank_check/bank_check_v1.rb +3 -1
- data/lib/mindee/product/us/driver_license/driver_license_v1.rb +3 -1
- data/lib/mindee/product/us/w9/w9_v1.rb +3 -1
- data/lib/mindee/product.rb +5 -0
- data/lib/mindee/version.rb +1 -1
- data/lib/mindee.rb +4 -0
- metadata +30 -2
@@ -34,8 +34,10 @@ module Mindee
|
|
34
34
|
out_str << "\n:Rotation applied: #{is_rotation_applied}"
|
35
35
|
out_str << "\n\nPrediction\n=========="
|
36
36
|
out_str << "\n#{@prediction.to_s.size.positive? ? "#{@prediction}\n" : ''}"
|
37
|
-
out_str << "\nPage Predictions\n================\n\n"
|
37
|
+
out_str << "\nPage Predictions\n================\n\n" unless @pages.empty?
|
38
38
|
out_str << @pages.map(&:to_s).join("\n\n")
|
39
|
+
out_str.rstrip!
|
40
|
+
out_str
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'generated_object_field'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Parsing
|
7
|
+
module Generated
|
8
|
+
# A list of values or objects, used in generated APIs.
|
9
|
+
class GeneratedListField
|
10
|
+
include Mindee::Parsing::Standard
|
11
|
+
include Mindee::Parsing::Generated
|
12
|
+
|
13
|
+
# Id of the page (as given by the API).
|
14
|
+
# @return [Integer]
|
15
|
+
attr_accessor :page_id
|
16
|
+
|
17
|
+
# List of word values
|
18
|
+
# @return [Array<GeneratedObjectField, StringField>]
|
19
|
+
attr_accessor :values
|
20
|
+
|
21
|
+
# Id of the page the object was found on.
|
22
|
+
# List of word values.
|
23
|
+
|
24
|
+
def initialize(raw_prediction, page_id = nil)
|
25
|
+
@values = []
|
26
|
+
|
27
|
+
raw_prediction.each do |value|
|
28
|
+
page_id = value['page_id'] if value.key?('page_id') && !value['page_id'].nil?
|
29
|
+
|
30
|
+
if Generated.generated_object?(value)
|
31
|
+
@values.push(GeneratedObjectField.new(value, page_id))
|
32
|
+
else
|
33
|
+
value_str = value.dup
|
34
|
+
value_str['value'] = value_str['value'].to_s if value_str.key?('value') && !value_str['value'].nil?
|
35
|
+
@values.push(StringField.new(value_str, page_id))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Return an Array of the contents of all values.
|
41
|
+
# @return [Array<String>]
|
42
|
+
def contents_list
|
43
|
+
@values.map(&:to_s)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return a string representation of all values.
|
47
|
+
def contents_string(separator = ' ')
|
48
|
+
@values.map(&:to_s).join(separator)
|
49
|
+
end
|
50
|
+
|
51
|
+
# String representation
|
52
|
+
def to_s
|
53
|
+
contents_string
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../common'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Parsing
|
7
|
+
# Generated fields and functions.
|
8
|
+
module Generated
|
9
|
+
# A JSON-like object, with miscellaneous values.
|
10
|
+
class GeneratedObjectField
|
11
|
+
include Mindee::Parsing::Standard
|
12
|
+
attr_accessor :page_id, :confidence, :raw_value
|
13
|
+
|
14
|
+
# Id of the page the object was found on.
|
15
|
+
# Confidence with which the value was assessed.
|
16
|
+
# Raw unprocessed value, as it was sent by the server.
|
17
|
+
|
18
|
+
def initialize(raw_prediction, page_id = nil)
|
19
|
+
@all_values = {}
|
20
|
+
item_page_id = nil
|
21
|
+
raw_prediction.each do |name, value|
|
22
|
+
case name
|
23
|
+
when 'page_id'
|
24
|
+
item_page_id = value
|
25
|
+
when 'polygon', 'rectangle', 'quadrangle', 'bounding_box'
|
26
|
+
handle_position_field(name, value, item_page_id)
|
27
|
+
when 'confidence'
|
28
|
+
@confidence = value
|
29
|
+
when 'raw_value'
|
30
|
+
@raw_value = value
|
31
|
+
else
|
32
|
+
handle_default_field(name, value)
|
33
|
+
end
|
34
|
+
@page_id = page_id || item_page_id
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# String representation that takes into account the level of indentation.
|
39
|
+
def str_level(level = 0)
|
40
|
+
indent = " #{' ' * level}"
|
41
|
+
out_str = ''
|
42
|
+
@all_values.each do |attr, value|
|
43
|
+
str_value = value.nil? ? '' : value.to_s
|
44
|
+
out_str += "\n#{indent}:#{attr}: #{str_value}".rstrip
|
45
|
+
end
|
46
|
+
"\n#{indent}#{out_str.strip}"
|
47
|
+
end
|
48
|
+
|
49
|
+
# Necessary overload of the method_missing method to allow for direct access to dynamic attributes without
|
50
|
+
# complicating usage too much
|
51
|
+
# Returns the corresponding attribute when asked.
|
52
|
+
#
|
53
|
+
# Otherwise, raises a NoMethodError.
|
54
|
+
#
|
55
|
+
# @param method_name [Symbol] The name of the method being called.
|
56
|
+
# @param _args [Array] Arguments passed to the method.
|
57
|
+
# @return [Object] The value associated with the method name in @all_values.
|
58
|
+
def method_missing(method_name, *_args)
|
59
|
+
super unless @all_values.key?(method_name.to_s)
|
60
|
+
@all_values[method_name.to_s]
|
61
|
+
end
|
62
|
+
|
63
|
+
# Necessary overload of the respond_to_missing? method to allow for direct access to dynamic attributes without
|
64
|
+
# complicating usage too much
|
65
|
+
# Returns true if the method name exists as a key in @all_values,
|
66
|
+
# indicating that the object can respond to the method.
|
67
|
+
# Otherwise, calls super to fallback to the default behavior.
|
68
|
+
#
|
69
|
+
# @param method_name [Symbol] The name of the method being checked.
|
70
|
+
# @param include_private [Boolean] Whether to include private methods in the check.
|
71
|
+
# @return [Boolean] True if the method can be responded to, false otherwise.
|
72
|
+
def respond_to_missing?(method_name, include_private = false)
|
73
|
+
@all_values.key?(method_name.to_s) || super
|
74
|
+
end
|
75
|
+
|
76
|
+
# String representation
|
77
|
+
def to_s
|
78
|
+
str_level
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def handle_position_field(name, value, item_page_id)
|
84
|
+
@all_values[name.to_s] =
|
85
|
+
PositionField.new({ name.to_s => value }, value_key: name.to_s, page_id: item_page_id)
|
86
|
+
end
|
87
|
+
|
88
|
+
def handle_default_field(name, value)
|
89
|
+
@all_values[name] = value.nil? ? nil : value.to_s
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.generated_object?(str_dict)
|
94
|
+
common_keys = [
|
95
|
+
'value',
|
96
|
+
'polygon',
|
97
|
+
'rectangle',
|
98
|
+
'page_id',
|
99
|
+
'confidence',
|
100
|
+
'quadrangle',
|
101
|
+
'values',
|
102
|
+
'raw_value',
|
103
|
+
]
|
104
|
+
str_dict.each_key { |key| return true unless common_keys.include?(key) }
|
105
|
+
false
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/lib/mindee/parsing.rb
CHANGED
@@ -19,7 +19,9 @@ module Mindee
|
|
19
19
|
@prediction = BarcodeReaderV1Document.new(prediction['prediction'], nil)
|
20
20
|
@pages = []
|
21
21
|
prediction['pages'].each do |page|
|
22
|
-
|
22
|
+
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
|
23
|
+
@pages.push(BarcodeReaderV1Page.new(page))
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
@@ -19,7 +19,9 @@ module Mindee
|
|
19
19
|
@prediction = CropperV1Document.new
|
20
20
|
@pages = []
|
21
21
|
prediction['pages'].each do |page|
|
22
|
-
|
22
|
+
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
|
23
|
+
@pages.push(CropperV1Page.new(page))
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
require_relative 'driver_license_v1_document'
|
5
|
+
require_relative 'driver_license_v1_page'
|
6
|
+
|
7
|
+
module Mindee
|
8
|
+
module Product
|
9
|
+
module EU
|
10
|
+
# EU Driver License module.
|
11
|
+
module DriverLicense
|
12
|
+
# EU Driver License V1 prediction inference.
|
13
|
+
class DriverLicenseV1 < Mindee::Parsing::Common::Inference
|
14
|
+
@endpoint_name = 'eu_driver_license'
|
15
|
+
@endpoint_version = '1'
|
16
|
+
|
17
|
+
# @param prediction [Hash]
|
18
|
+
def initialize(prediction)
|
19
|
+
super
|
20
|
+
@prediction = DriverLicenseV1Document.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(DriverLicenseV1Page.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,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Product
|
7
|
+
module EU
|
8
|
+
module DriverLicense
|
9
|
+
# EU Driver License V1 document prediction.
|
10
|
+
class DriverLicenseV1Document < Mindee::Parsing::Common::Prediction
|
11
|
+
include Mindee::Parsing::Standard
|
12
|
+
# EU driver license holders address
|
13
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
14
|
+
attr_reader :address
|
15
|
+
# EU driver license holders categories
|
16
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
17
|
+
attr_reader :category
|
18
|
+
# Country code extracted as a string.
|
19
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
20
|
+
attr_reader :country_code
|
21
|
+
# The date of birth of the document holder
|
22
|
+
# @return [Mindee::Parsing::Standard::DateField]
|
23
|
+
attr_reader :date_of_birth
|
24
|
+
# ID number of the Document.
|
25
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
26
|
+
attr_reader :document_id
|
27
|
+
# Date the document expires
|
28
|
+
# @return [Mindee::Parsing::Standard::DateField]
|
29
|
+
attr_reader :expiry_date
|
30
|
+
# First name(s) of the driver license holder
|
31
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
32
|
+
attr_reader :first_name
|
33
|
+
# Authority that issued the document
|
34
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
35
|
+
attr_reader :issue_authority
|
36
|
+
# Date the document was issued
|
37
|
+
# @return [Mindee::Parsing::Standard::DateField]
|
38
|
+
attr_reader :issue_date
|
39
|
+
# Last name of the driver license holder.
|
40
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
41
|
+
attr_reader :last_name
|
42
|
+
# Machine-readable license number
|
43
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
44
|
+
attr_reader :mrz
|
45
|
+
# Place where the driver license holder was born
|
46
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
47
|
+
attr_reader :place_of_birth
|
48
|
+
|
49
|
+
# @param prediction [Hash]
|
50
|
+
# @param page_id [Integer, nil]
|
51
|
+
def initialize(prediction, page_id)
|
52
|
+
super()
|
53
|
+
@address = StringField.new(prediction['address'], page_id)
|
54
|
+
@category = StringField.new(prediction['category'], page_id)
|
55
|
+
@country_code = StringField.new(prediction['country_code'], page_id)
|
56
|
+
@date_of_birth = DateField.new(prediction['date_of_birth'], page_id)
|
57
|
+
@document_id = StringField.new(prediction['document_id'], page_id)
|
58
|
+
@expiry_date = DateField.new(prediction['expiry_date'], page_id)
|
59
|
+
@first_name = StringField.new(prediction['first_name'], page_id)
|
60
|
+
@issue_authority = StringField.new(prediction['issue_authority'], page_id)
|
61
|
+
@issue_date = DateField.new(prediction['issue_date'], page_id)
|
62
|
+
@last_name = StringField.new(prediction['last_name'], page_id)
|
63
|
+
@mrz = StringField.new(prediction['mrz'], page_id)
|
64
|
+
@place_of_birth = StringField.new(prediction['place_of_birth'], page_id)
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [String]
|
68
|
+
def to_s
|
69
|
+
out_str = String.new
|
70
|
+
out_str << "\n:Country Code: #{@country_code}".rstrip
|
71
|
+
out_str << "\n:Document ID: #{@document_id}".rstrip
|
72
|
+
out_str << "\n:Driver License Category: #{@category}".rstrip
|
73
|
+
out_str << "\n:Last Name: #{@last_name}".rstrip
|
74
|
+
out_str << "\n:First Name: #{@first_name}".rstrip
|
75
|
+
out_str << "\n:Date Of Birth: #{@date_of_birth}".rstrip
|
76
|
+
out_str << "\n:Place Of Birth: #{@place_of_birth}".rstrip
|
77
|
+
out_str << "\n:Expiry Date: #{@expiry_date}".rstrip
|
78
|
+
out_str << "\n:Issue Date: #{@issue_date}".rstrip
|
79
|
+
out_str << "\n:Issue Authority: #{@issue_authority}".rstrip
|
80
|
+
out_str << "\n:MRZ: #{@mrz}".rstrip
|
81
|
+
out_str << "\n:Address: #{@address}".rstrip
|
82
|
+
out_str[1..].to_s
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
require_relative 'driver_license_v1_document'
|
5
|
+
|
6
|
+
module Mindee
|
7
|
+
module Product
|
8
|
+
module EU
|
9
|
+
module DriverLicense
|
10
|
+
# EU Driver License V1 page.
|
11
|
+
class DriverLicenseV1Page < Mindee::Parsing::Common::Page
|
12
|
+
# @param prediction [Hash]
|
13
|
+
def initialize(prediction)
|
14
|
+
super(prediction)
|
15
|
+
@prediction = DriverLicenseV1PagePrediction.new(
|
16
|
+
prediction['prediction'],
|
17
|
+
prediction['id']
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# EU Driver License V1 page prediction.
|
23
|
+
class DriverLicenseV1PagePrediction < DriverLicenseV1Document
|
24
|
+
include Mindee::Parsing::Standard
|
25
|
+
|
26
|
+
# Has a photo of the EU driver license holder
|
27
|
+
# @return [Mindee::Parsing::Standard::PositionField]
|
28
|
+
attr_reader :photo
|
29
|
+
# Has a signature of the EU driver license holder
|
30
|
+
# @return [Mindee::Parsing::Standard::PositionField]
|
31
|
+
attr_reader :signature
|
32
|
+
|
33
|
+
# @param prediction [Hash]
|
34
|
+
# @param page_id [Integer, nil]
|
35
|
+
def initialize(prediction, page_id)
|
36
|
+
@photo = PositionField.new(prediction['photo'], page_id)
|
37
|
+
@signature = PositionField.new(prediction['signature'], page_id)
|
38
|
+
super(prediction, page_id)
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [String]
|
42
|
+
def to_s
|
43
|
+
out_str = String.new
|
44
|
+
out_str << "\n:Photo: #{@photo}".rstrip
|
45
|
+
out_str << "\n:Signature: #{@signature}".rstrip
|
46
|
+
out_str << "\n#{super}"
|
47
|
+
out_str
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -20,7 +20,9 @@ module Mindee
|
|
20
20
|
@prediction = LicensePlateV1Document.new(prediction['prediction'], nil)
|
21
21
|
@pages = []
|
22
22
|
prediction['pages'].each do |page|
|
23
|
-
|
23
|
+
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
|
24
|
+
@pages.push(LicensePlateV1Page.new(page))
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -19,7 +19,9 @@ module Mindee
|
|
19
19
|
@prediction = FinancialDocumentV1Document.new(prediction['prediction'], nil)
|
20
20
|
@pages = []
|
21
21
|
prediction['pages'].each do |page|
|
22
|
-
|
22
|
+
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
|
23
|
+
@pages.push(FinancialDocumentV1Page.new(page))
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
@@ -20,7 +20,9 @@ module Mindee
|
|
20
20
|
@prediction = BankAccountDetailsV1Document.new(prediction['prediction'], nil)
|
21
21
|
@pages = []
|
22
22
|
prediction['pages'].each do |page|
|
23
|
-
|
23
|
+
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
|
24
|
+
@pages.push(BankAccountDetailsV1Page.new(page))
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -20,7 +20,9 @@ module Mindee
|
|
20
20
|
@prediction = BankAccountDetailsV2Document.new(prediction['prediction'], nil)
|
21
21
|
@pages = []
|
22
22
|
prediction['pages'].each do |page|
|
23
|
-
|
23
|
+
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
|
24
|
+
@pages.push(BankAccountDetailsV2Page.new(page))
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
require_relative 'bank_statement_v1_document'
|
5
|
+
require_relative 'bank_statement_v1_page'
|
6
|
+
|
7
|
+
module Mindee
|
8
|
+
module Product
|
9
|
+
module FR
|
10
|
+
# Bank Statement (FR) module.
|
11
|
+
module BankStatement
|
12
|
+
# Bank Statement (FR) V1 prediction inference.
|
13
|
+
class BankStatementV1 < Mindee::Parsing::Common::Inference
|
14
|
+
@endpoint_name = 'bank_statement_fr'
|
15
|
+
@endpoint_version = '1'
|
16
|
+
|
17
|
+
# @param prediction [Hash]
|
18
|
+
def initialize(prediction)
|
19
|
+
super
|
20
|
+
@prediction = BankStatementV1Document.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(BankStatementV1Page.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,130 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
require_relative 'bank_statement_v1_transaction'
|
5
|
+
|
6
|
+
module Mindee
|
7
|
+
module Product
|
8
|
+
module FR
|
9
|
+
module BankStatement
|
10
|
+
# Bank Statement (FR) V1 document prediction.
|
11
|
+
class BankStatementV1Document < Mindee::Parsing::Common::Prediction
|
12
|
+
include Mindee::Parsing::Standard
|
13
|
+
# The unique identifier for a customer's account in the bank's system.
|
14
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
15
|
+
attr_reader :account_number
|
16
|
+
# The physical location of the bank where the statement was issued.
|
17
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
18
|
+
attr_reader :bank_address
|
19
|
+
# The name of the bank that issued the statement.
|
20
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
21
|
+
attr_reader :bank_name
|
22
|
+
# The address of the client associated with the bank statement.
|
23
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
24
|
+
attr_reader :client_address
|
25
|
+
# The name of the client who owns the bank statement.
|
26
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
27
|
+
attr_reader :client_name
|
28
|
+
# The final amount of money in the account at the end of the statement period.
|
29
|
+
# @return [Mindee::Parsing::Standard::AmountField]
|
30
|
+
attr_reader :closing_balance
|
31
|
+
# The initial amount of money in an account at the start of the period.
|
32
|
+
# @return [Mindee::Parsing::Standard::AmountField]
|
33
|
+
attr_reader :opening_balance
|
34
|
+
# The date on which the bank statement was generated.
|
35
|
+
# @return [Mindee::Parsing::Standard::DateField]
|
36
|
+
attr_reader :statement_date
|
37
|
+
# The date when the statement period ends.
|
38
|
+
# @return [Mindee::Parsing::Standard::DateField]
|
39
|
+
attr_reader :statement_end_date
|
40
|
+
# The date when the bank statement period begins.
|
41
|
+
# @return [Mindee::Parsing::Standard::DateField]
|
42
|
+
attr_reader :statement_start_date
|
43
|
+
# The total amount of money deposited into the account.
|
44
|
+
# @return [Mindee::Parsing::Standard::AmountField]
|
45
|
+
attr_reader :total_credits
|
46
|
+
# The total amount of money debited from the account.
|
47
|
+
# @return [Mindee::Parsing::Standard::AmountField]
|
48
|
+
attr_reader :total_debits
|
49
|
+
# The list of values that represent the financial transactions recorded in a bank statement.
|
50
|
+
# @return [Array<Mindee::Product::FR::BankStatement::BankStatementV1Transaction>]
|
51
|
+
attr_reader :transactions
|
52
|
+
|
53
|
+
# @param prediction [Hash]
|
54
|
+
# @param page_id [Integer, nil]
|
55
|
+
def initialize(prediction, page_id)
|
56
|
+
super()
|
57
|
+
@account_number = StringField.new(prediction['account_number'], page_id)
|
58
|
+
@bank_address = StringField.new(prediction['bank_address'], page_id)
|
59
|
+
@bank_name = StringField.new(prediction['bank_name'], page_id)
|
60
|
+
@client_address = StringField.new(prediction['client_address'], page_id)
|
61
|
+
@client_name = StringField.new(prediction['client_name'], page_id)
|
62
|
+
@closing_balance = AmountField.new(prediction['closing_balance'], page_id)
|
63
|
+
@opening_balance = AmountField.new(prediction['opening_balance'], page_id)
|
64
|
+
@statement_date = DateField.new(prediction['statement_date'], page_id)
|
65
|
+
@statement_end_date = DateField.new(prediction['statement_end_date'], page_id)
|
66
|
+
@statement_start_date = DateField.new(prediction['statement_start_date'], page_id)
|
67
|
+
@total_credits = AmountField.new(prediction['total_credits'], page_id)
|
68
|
+
@total_debits = AmountField.new(prediction['total_debits'], page_id)
|
69
|
+
@transactions = []
|
70
|
+
prediction['transactions'].each do |item|
|
71
|
+
@transactions.push(BankStatementV1Transaction.new(item, page_id))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [String]
|
76
|
+
def to_s
|
77
|
+
transactions = transactions_to_s
|
78
|
+
out_str = String.new
|
79
|
+
out_str << "\n:Account Number: #{@account_number}".rstrip
|
80
|
+
out_str << "\n:Bank Name: #{@bank_name}".rstrip
|
81
|
+
out_str << "\n:Bank Address: #{@bank_address}".rstrip
|
82
|
+
out_str << "\n:Client Name: #{@client_name}".rstrip
|
83
|
+
out_str << "\n:Client Address: #{@client_address}".rstrip
|
84
|
+
out_str << "\n:Statement Date: #{@statement_date}".rstrip
|
85
|
+
out_str << "\n:Statement Start Date: #{@statement_start_date}".rstrip
|
86
|
+
out_str << "\n:Statement End Date: #{@statement_end_date}".rstrip
|
87
|
+
out_str << "\n:Opening Balance: #{@opening_balance}".rstrip
|
88
|
+
out_str << "\n:Closing Balance: #{@closing_balance}".rstrip
|
89
|
+
out_str << "\n:Transactions:"
|
90
|
+
out_str << transactions
|
91
|
+
out_str << "\n:Total Debits: #{@total_debits}".rstrip
|
92
|
+
out_str << "\n:Total Credits: #{@total_credits}".rstrip
|
93
|
+
out_str[1..].to_s
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
# @param char [String]
|
99
|
+
# @return [String]
|
100
|
+
def transactions_separator(char)
|
101
|
+
out_str = String.new
|
102
|
+
out_str << ' '
|
103
|
+
out_str << "+#{char * 11}"
|
104
|
+
out_str << "+#{char * 12}"
|
105
|
+
out_str << "+#{char * 38}"
|
106
|
+
out_str << '+'
|
107
|
+
out_str
|
108
|
+
end
|
109
|
+
|
110
|
+
# @return [String]
|
111
|
+
def transactions_to_s
|
112
|
+
return '' if @transactions.empty?
|
113
|
+
|
114
|
+
line_items = @transactions.map(&:to_table_line).join("\n#{transactions_separator('-')}\n ")
|
115
|
+
out_str = String.new
|
116
|
+
out_str << "\n#{transactions_separator('-')}"
|
117
|
+
out_str << "\n |"
|
118
|
+
out_str << ' Amount |'
|
119
|
+
out_str << ' Date |'
|
120
|
+
out_str << ' Description |'
|
121
|
+
out_str << "\n#{transactions_separator('=')}"
|
122
|
+
out_str << "\n #{line_items}"
|
123
|
+
out_str << "\n#{transactions_separator('-')}"
|
124
|
+
out_str
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
require_relative 'bank_statement_v1_document'
|
5
|
+
|
6
|
+
module Mindee
|
7
|
+
module Product
|
8
|
+
module FR
|
9
|
+
module BankStatement
|
10
|
+
# Bank Statement (FR) V1 page.
|
11
|
+
class BankStatementV1Page < Mindee::Parsing::Common::Page
|
12
|
+
# @param prediction [Hash]
|
13
|
+
def initialize(prediction)
|
14
|
+
super(prediction)
|
15
|
+
@prediction = BankStatementV1PagePrediction.new(
|
16
|
+
prediction['prediction'],
|
17
|
+
prediction['id']
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Bank Statement (FR) V1 page prediction.
|
23
|
+
class BankStatementV1PagePrediction < BankStatementV1Document
|
24
|
+
# @return [String]
|
25
|
+
def to_s
|
26
|
+
out_str = String.new
|
27
|
+
out_str << "\n#{super}"
|
28
|
+
out_str
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|