|
| 1 | +--- |
| 2 | +title: FR Bank Statement (FR) OCR Ruby |
| 3 | +--- |
| 4 | +The Ruby OCR SDK supports the [Bank Statement (FR) API](https://platform.mindee.com/mindee/bank_statement_fr). |
| 5 | + |
| 6 | +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_statement_fr/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. |
| 7 | + |
| 8 | + |
| 9 | +# Quick-Start |
| 10 | +```rb |
| 11 | +require 'mindee' |
| 12 | + |
| 13 | +# Init a new client |
| 14 | +mindee_client = Mindee::Client.new(api_key: 'my-api-key') |
| 15 | + |
| 16 | +# Load a file from disk |
| 17 | +input_source = mindee_client.source_from_path('/path/to/the/file.ext') |
| 18 | + |
| 19 | +# Parse the file |
| 20 | +result = mindee_client.enqueue_and_parse( |
| 21 | + input_source, |
| 22 | + Mindee::Product::FR::BankStatement::BankStatementV1 |
| 23 | +) |
| 24 | + |
| 25 | +# Print a full summary of the parsed data in RST format |
| 26 | +puts result.document |
| 27 | + |
| 28 | +# Print the document-level parsed data |
| 29 | +# puts result.document.inference.prediction |
| 30 | +``` |
| 31 | + |
| 32 | +**Output (RST):** |
| 33 | +```rst |
| 34 | +``` |
| 35 | + |
| 36 | +# Field Types |
| 37 | +## Standard Fields |
| 38 | +These fields are generic and used in several products. |
| 39 | + |
| 40 | +### Basic Field |
| 41 | +Each prediction object contains a set of fields that inherit from the generic `Field` class. |
| 42 | +A typical `Field` object will have the following attributes: |
| 43 | + |
| 44 | +* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. |
| 45 | +* **confidence** (Float, nil): the confidence score of the field prediction. |
| 46 | +* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. |
| 47 | +* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. |
| 48 | +* **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level. |
| 49 | +* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). |
| 50 | + |
| 51 | + |
| 52 | +Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string. |
| 53 | + |
| 54 | + |
| 55 | +### Amount Field |
| 56 | +The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`). |
| 57 | + |
| 58 | +### Date Field |
| 59 | +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: |
| 60 | + |
| 61 | +* **date_object** (`Date`): an accessible representation of the value as a JavaScript object. |
| 62 | + |
| 63 | +### String Field |
| 64 | +The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`). |
| 65 | + |
| 66 | +## Specific Fields |
| 67 | +Fields which are specific to this product; they are not used in any other product. |
| 68 | + |
| 69 | +### Transactions Field |
| 70 | +The list of values that represent the financial transactions recorded in a bank statement. |
| 71 | + |
| 72 | +A `BankStatementV1Transaction` implements the following attributes: |
| 73 | + |
| 74 | +* `amount` (Float): The monetary amount of the transaction. |
| 75 | +* `date` (String): The date on which the transaction occurred. |
| 76 | +* `description` (String): The additional information about the transaction. |
| 77 | + |
| 78 | +# Attributes |
| 79 | +The following fields are extracted for Bank Statement (FR) V1: |
| 80 | + |
| 81 | +## Account Number |
| 82 | +**account_number** ([StringField](#string-field)): The unique identifier for a customer's account in the bank's system. |
| 83 | + |
| 84 | +```rb |
| 85 | +puts result.document.inference.prediction.account_number.value |
| 86 | +``` |
| 87 | + |
| 88 | +## Bank Address |
| 89 | +**bank_address** ([StringField](#string-field)): The physical location of the bank where the statement was issued. |
| 90 | + |
| 91 | +```rb |
| 92 | +puts result.document.inference.prediction.bank_address.value |
| 93 | +``` |
| 94 | + |
| 95 | +## Bank Name |
| 96 | +**bank_name** ([StringField](#string-field)): The name of the bank that issued the statement. |
| 97 | + |
| 98 | +```rb |
| 99 | +puts result.document.inference.prediction.bank_name.value |
| 100 | +``` |
| 101 | + |
| 102 | +## Client Address |
| 103 | +**client_address** ([StringField](#string-field)): The address of the client associated with the bank statement. |
| 104 | + |
| 105 | +```rb |
| 106 | +puts result.document.inference.prediction.client_address.value |
| 107 | +``` |
| 108 | + |
| 109 | +## Client Name |
| 110 | +**client_name** ([StringField](#string-field)): The name of the client who owns the bank statement. |
| 111 | + |
| 112 | +```rb |
| 113 | +puts result.document.inference.prediction.client_name.value |
| 114 | +``` |
| 115 | + |
| 116 | +## Closing Balance |
| 117 | +**closing_balance** ([AmountField](#amount-field)): The final amount of money in the account at the end of the statement period. |
| 118 | + |
| 119 | +```rb |
| 120 | +puts result.document.inference.prediction.closing_balance.value |
| 121 | +``` |
| 122 | + |
| 123 | +## Opening Balance |
| 124 | +**opening_balance** ([AmountField](#amount-field)): The initial amount of money in an account at the start of the period. |
| 125 | + |
| 126 | +```rb |
| 127 | +puts result.document.inference.prediction.opening_balance.value |
| 128 | +``` |
| 129 | + |
| 130 | +## Statement Date |
| 131 | +**statement_date** ([DateField](#date-field)): The date on which the bank statement was generated. |
| 132 | + |
| 133 | +```rb |
| 134 | +puts result.document.inference.prediction.statement_date.value |
| 135 | +``` |
| 136 | + |
| 137 | +## Statement End Date |
| 138 | +**statement_end_date** ([DateField](#date-field)): The date when the statement period ends. |
| 139 | + |
| 140 | +```rb |
| 141 | +puts result.document.inference.prediction.statement_end_date.value |
| 142 | +``` |
| 143 | + |
| 144 | +## Statement Start Date |
| 145 | +**statement_start_date** ([DateField](#date-field)): The date when the bank statement period begins. |
| 146 | + |
| 147 | +```rb |
| 148 | +puts result.document.inference.prediction.statement_start_date.value |
| 149 | +``` |
| 150 | + |
| 151 | +## Total Credits |
| 152 | +**total_credits** ([AmountField](#amount-field)): The total amount of money deposited into the account. |
| 153 | + |
| 154 | +```rb |
| 155 | +puts result.document.inference.prediction.total_credits.value |
| 156 | +``` |
| 157 | + |
| 158 | +## Total Debits |
| 159 | +**total_debits** ([AmountField](#amount-field)): The total amount of money debited from the account. |
| 160 | + |
| 161 | +```rb |
| 162 | +puts result.document.inference.prediction.total_debits.value |
| 163 | +``` |
| 164 | + |
| 165 | +## Transactions |
| 166 | +**transactions** (Array<[BankStatementV1Transaction](#transactions-field)>): The list of values that represent the financial transactions recorded in a bank statement. |
| 167 | + |
| 168 | +```rb |
| 169 | +for transactions_elem in result.document.inference.prediction.transactions do |
| 170 | + puts transactions_elem.value |
| 171 | +end |
| 172 | +``` |
| 173 | + |
| 174 | +# Questions? |
| 175 | +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw) |
0 commit comments