Ruby: OCR Invoices & Receipts in SecondsRuby: OCR Invoices & Receipts in Seconds

May 17, 2023
4 mins read

Ruby (the programming language) is a fast and fluid web development language highly recommended if you have particular beef with Python. It was created in 1995 (four years after Python) by a man named Yukihiro “Matz” Matsumoto in Japan after the creator of Python presumably keyed his car. Ruby later rose in popularity between 2010 and 2016, going from a language only used in Japan to a language praised as the Python alternative.

Ruby still stands as the 17th most widely used language in the world, and considering we at Veryfi already made libraries for Go, Java, Python, Javascript, Swift, and C#, it was only a matter of time before we made a library for Ruby too.

Turn-Key 🗝️ Data Extraction

It’s simple. We streamline the process of extracting data from financial documents like receipts, bills, and invoices. We do it all automatically using machines-end-to-end (minus the human piece) and with minimal hassle in seconds.

If you are building an expense management app or a bill pay solution or even wanting to automate your company’s purchasing cycle then Veryfi is your best bet because you can get started in 1 minute without the hassles of setups or model training. How fast you deploy Veryfi is a function of how fast can you develop. Basically, Veryfi is read-to-go out of the box.

Turn a document into data in seconds

An invoice from Rumpke
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
{
"account_number": "1234987650",
"bill_to": {
"address": "1234 CUSTOMER AVE\nCLEVELAND OH 44114",
"name": "JOHN DOE"
},
"category": "Job Supplies",
"created_date": "2020-08-20 01:50:38",
"currency_code": "USD",
"date": "2020-08-04 00:00:00",
"default_category": "Job Supplies",
"discount": 0,
"due_date": "2020-08-19",
"external_id": "",
"id": 29697870,
"img_file_name": "92233902-c94a-491d-a4f9-0d61f9407cd2.pdf",
"img_thumbnail_url": "https://cdn.veryfi.com/receipts/92233902-c94a-491d-a4f9-0d61f9407cd2_t.jpg",
"img_url": "https://cdn.veryfi.com/receipts/92233902-c94a-491d-a4f9-0d61f9407cd2.pdf",
"invoice_number": "0998811",
"line_items": [
{
"date": "2020-08-01",
"description": "2YD FL/MONTH-MSW",
"discount": 0,
"id": 25052118,
"order": 0,
"price": 116.32,
"quantity": 1,
"reference": "",
"sku": "",
"tax": 0,
"tax_rate": 0,
"total": 116.32,
"type": "product",
"unit_of_measure": ""
...
...
...
{ "account_number": "1234987650", "bill_to": { "address": "1234 CUSTOMER AVE\nCLEVELAND OH 44114", "name": "JOHN DOE" }, "category": "Job Supplies", "created_date": "2020-08-20 01:50:38", "currency_code": "USD", "date": "2020-08-04 00:00:00", "default_category": "Job Supplies", "discount": 0, "due_date": "2020-08-19", "external_id": "", "id": 29697870, "img_file_name": "92233902-c94a-491d-a4f9-0d61f9407cd2.pdf", "img_thumbnail_url": "https://cdn.veryfi.com/receipts/92233902-c94a-491d-a4f9-0d61f9407cd2_t.jpg", "img_url": "https://cdn.veryfi.com/receipts/92233902-c94a-491d-a4f9-0d61f9407cd2.pdf", "invoice_number": "0998811", "line_items": [ { "date": "2020-08-01", "description": "2YD FL/MONTH-MSW", "discount": 0, "id": 25052118, "order": 0, "price": 116.32, "quantity": 1, "reference": "", "sku": "", "tax": 0, "tax_rate": 0, "total": 116.32, "type": "product", "unit_of_measure": "" ... ... ...
{
  "account_number": "1234987650",
  "bill_to": {
    "address": "1234 CUSTOMER AVE\nCLEVELAND OH 44114",
    "name": "JOHN DOE"
  },
  "category": "Job Supplies",
  "created_date": "2020-08-20 01:50:38",
  "currency_code": "USD",
  "date": "2020-08-04 00:00:00",
  "default_category": "Job Supplies",
  "discount": 0,
  "due_date": "2020-08-19",
  "external_id": "",
  "id": 29697870,
  "img_file_name": "92233902-c94a-491d-a4f9-0d61f9407cd2.pdf",
  "img_thumbnail_url": "https://cdn.veryfi.com/receipts/92233902-c94a-491d-a4f9-0d61f9407cd2_t.jpg",
  "img_url": "https://cdn.veryfi.com/receipts/92233902-c94a-491d-a4f9-0d61f9407cd2.pdf",
  "invoice_number": "0998811",
  "line_items": [
    {
      "date": "2020-08-01",
      "description": "2YD FL/MONTH-MSW",
      "discount": 0,
      "id": 25052118,
      "order": 0,
      "price": 116.32,
      "quantity": 1,
      "reference": "",
      "sku": "",
      "tax": 0,
      "tax_rate": 0,
      "total": 116.32,
      "type": "product",
      "unit_of_measure": ""
	...
	...
	...

We use advanced optical and intelligent character recognition in order to extract data fields from receipts and invoice–all in a matter of seconds. It doesn’t matter if it’s a nice, clean PDF or a blurry, shaky photo. With Veryfi, we can process a stack of thousands of invoices and receipts in minutes and save you time and money.
So let’s take a look at how we can process a document with Veryfi’s Ruby SDK

Superpowers in 3 Steps

Step 1

Import Veryfi into your project and create a client object by providing your ID, secret, username, and API key. You can find these all in your Veryfi Hub if you already have an account or you start a free trial.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
require 'veryfi'
veryfi_client = Veryfi::Client.new(
client_id: 'your_client_id',
client_secret: 'your_client_secret',
username: 'your_username',
api_key: 'your_password'
)
require 'veryfi' veryfi_client = Veryfi::Client.new( client_id: 'your_client_id', client_secret: 'your_client_secret', username: 'your_username', api_key: 'your_password' )
require 'veryfi' 

veryfi_client = Veryfi::Client.new(
  client_id: 'your_client_id',
  client_secret: 'your_client_secret',
  username: 'your_username',
  api_key: 'your_password'
)

Step 2

Set your parameters for processing. Although you have a bunch of options for customization, we’ll just stick with a basic file path and some categories our invoice might fall under.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
params = {
file_path: './test/invoice.jpg',
categories: [
'Advertising & Marketing',
'Automotive'
]
}
params = { file_path: './test/invoice.jpg', categories: [ 'Advertising & Marketing', 'Automotive' ] }
params = {
  file_path: './test/invoice.jpg',
  categories: [
    'Advertising & Marketing',
    'Automotive'
  ]
}

Step 3

Send a request through your client object and print out your response.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
response = veryfi_client.document.process(params)
puts response
response = veryfi_client.document.process(params) puts response
response = veryfi_client.document.process(params)

puts response

And that’s it!

In just three simple steps we just extracted that JSON object of your document without any hassle or interference on your part.

So don’t waste your time processing financial documents. Sign up for a free trial today!

API Portal Inbox

On hub.veryfi.com, you can also see all the documents that are captured.

Veryfi Portal

Watch Ruby SDK Video

Here’s the video link for the tutorial if you want to see everything in action in a video format. We’re also sharing some tips on how to navigate the hub.veryfi.com to see more detailed results as well as other integrations.

Feedback

GitHub issues: if you want to leave public feedback, please open a GitHub issue in the Veryfi Ruby SDK Github Repository. Doing so may also help any other users experiencing the same problem and grow the conversation. We make sure to evaluate issues on our end too, so we can address them in future releases.

Contact us: If you want to speak with our team privately to ask questions, give feedback, or make a feature request, please email us at support@veryfi.com.

Contributing

You can always make pull requests for new fixes or features to the Veryfi Ruby SDK. Please ensure your requests are made under the MIT license. Our team also reviews any requests before they’re merged, so unit tests are gladly accepted.

Special Thanks!

Thank you Hoanh @ Veryfi for the stellar Ruby write-up.

Veryfi SDKsVeryfi SDKs

Showing 54 SDK cards

Python

mcp-server

Model context protocol server with Veryfi API access

Kotlin

veryfi-android

Android kotlin module for communicating with the Veryfi OCR API

C#

veryfi-csharp

This is the official C# client library for communicating with the Veryfi OCR API. || read: https://veryfi.com/csharp

Dart

veryfi-dart

Dart module for communicating with the Veryfi OCR API

HTML

veryfi-docs

All documentation related to Veryfi API

HTML

veryfi-docs-v2

Dynamic documentation

Go

veryfi-go

Go module for communicating with the Veryfi OCR API.

Java

veryfi-java

Java module for communicating with the Veryfi OCR API.

Kotlin

veryfi-kotlin

Kotlin Library for communicating with the Veryfi OCR API

JavaScript

veryfi-nodejs

Node.js module for communicating with the Veryfi OCR API. || read: https://veryfi.com/nodejs

PHP

veryfi-php

PHP module for communicating with the Veryfi OCR API.

Python

veryfi-python

Python module for communicating with the Veryfi OCR API.

Ruby

veryfi-ruby

Ruby gem for communicating with the Veryfi OCR API.

Rust

veryfi-rust

Rust module for communicating with the Veryfi OCR API

Swift

veryfi-swift

Swift framework for communicating with the Veryfi OCR API

Kotlin

veryfi-lens-bank-statements-android-demo

Example about how to user Veryfi Lens for Bank Statements

Swift

veryfi-lens-bank-statements-ios-demo

Example about how to use Veryfi Lens

Kotlin

veryfi-lens-barcodes-android-demo

Example about how to user Veryfi Lens for Barcodes

Swift

veryfi-lens-barcodes-ios-demo

Example about how to user Veryfi Lens for Barcodes

Kotlin

veryfi-lens-business-cards-android-demo

Example codes about how to use Veryfi Lens SDKs

Swift

veryfi-lens-business-cards-ios-demo

Example codes about how to use Veryfi Lens SDKs

Kotlin

veryfi-lens-checks-android-demo

Example codes about how to use Veryfi Lens SDKs

Swift

veryfi-lens-checks-ios-demo

Example codes about how to use Veryfi Lens SDKs

Vue

veryfi-lens-cordova-demo

Example codes about how to use Veryfi Lens SDKs

Kotlin

veryfi-lens-credit-cards-android-demo

Example codes about how to use Veryfi Lens SDKs

Swift

veryfi-lens-credit-cards-ios-demo

Example codes about how to use Veryfi Lens SDKs

JavaScript

veryfi-lens-demo-vanillajs

null

Dart

veryfi-lens-flutter-demo

Example Demo App about how to use our Flutter wrapper

Kotlin

veryfi-lens-headless-credit-cards-android-demo

Example codes about how to use Veryfi Lens SDKs

Swift

veryfi-lens-headless-credit-cards-ios-demo

Example codes about how to use Veryfi Lens SDKs

Kotlin

veryfi-lens-headless-receipts-android-demo

Example codes about how to use Veryfi Lens SDKs

Swift

veryfi-lens-headless-receipts-ios-demo

Example codes about how to use Veryfi Lens SDKs

TypeScript

veryfi-lens-ionic-capacitor-demo

Example codes about how to use Veryfi Lens SDKs

Kotlin

veryfi-lens-long-receipts-android-demo

Example codes about how to use Veryfi Lens SDKs

Swift

veryfi-lens-long-receipts-ios-demo

Example codes about how to use Veryfi Lens SDKs

C#

veryfi-lens-net-demo

Veryfi Lens Demo for .NET

Kotlin

veryfi-lens-ocr-android-demo

Veryfi Lens OCR to read codes, numbers and short text

Swift

veryfi-lens-ocr-ios-demo

Example project about how to use Veryfi Lens OCR SDK

TypeScript

veryfi-lens-react-native-demo

Example Demo App about how to use our react native wrapper

TypeScript

veryfi-lens-react-native-expo-demo

Example Demo App about how to use our react native wrapper

Kotlin

veryfi-lens-receipts-android-demo

Example codes about how to use Veryfi Lens SDKs

Swift

veryfi-lens-receipts-ios-demo

Example codes about how to use Veryfi Lens SDKs

JavaScript

veryfi-lens-socket

Lens for Browser socket sdk

Swift

veryfi-lens-swiftui-ios-demo

Veryfi Lens example about how to user our Lens SDK inside a SwiftUI iOS project

Kotlin

veryfi-lens-w2-android-demo

Example codes about how to use Veryfi Lens SDKs

Swift

veryfi-lens-w2-ios-demo

Example codes about how to use Veryfi Lens SDKs

Kotlin

veryfi-lens-w9-android-demo

Example codes about how to use Veryfi Lens SDKs

Swift

veryfi-lens-w9-ios-demo

Example codes about how to use Veryfi Lens SDKs

JavaScript

veryfi-lens-wasm

null

JavaScript

veryfi-lens-web-demo-angular

Veryfi Lens for Web Demo Angular App

JavaScript

veryfi-lens-web-demo-express

Veryfi Lens for Web SDK Demo

TypeScript

veryfi-lens-web-demo-react

Veryfi Lens for Web Demo React App

JavaScript

veryfi-lens-web-demo-svelte

null

C#

veryfi-lens-xamarin-demo

Example codes about how to use Veryfi Lens SDKs