Class: Mindee::V1::Product::Receipt::ReceiptV5Document

Inherits:
Mindee::V1::Parsing::Common::Prediction show all
Includes:
Mindee::V1::Parsing::Standard
Defined in:
lib/mindee/v1/product/receipt/receipt_v5_document.rb,
sig/mindee/v1/product/receipt/receipt_v5_document.rbs

Overview

Receipt API version 5.4 document data.

Direct Known Subclasses

ReceiptV5PagePrediction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prediction, page_id) ⇒ ReceiptV5Document

Returns a new instance of ReceiptV5Document.

Parameters:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 68

def initialize(prediction, page_id)
  super
  @category = Parsing::Standard::ClassificationField.new(
    prediction['category'],
    page_id
  )
  @date = Parsing::Standard::DateField.new(prediction['date'], page_id)
  @document_type = Parsing::Standard::ClassificationField.new(
    prediction['document_type'],
    page_id
  )
  @line_items = Product::Receipt::ReceiptV5LineItems.new(prediction['line_items'], page_id)
  @locale = Parsing::Standard::LocaleField.new(
    prediction['locale'],
    page_id
  )
  @receipt_number = Parsing::Standard::StringField.new(
    prediction['receipt_number'],
    page_id
  )
  @subcategory = Parsing::Standard::ClassificationField.new(
    prediction['subcategory'],
    page_id
  )
  @supplier_address = Parsing::Standard::StringField.new(
    prediction['supplier_address'],
    page_id
  )
  @supplier_company_registrations = [] # : Array[Parsing::Standard::CompanyRegistrationField]
  prediction['supplier_company_registrations'].each do |item|
    @supplier_company_registrations.push(Parsing::Standard::CompanyRegistrationField.new(item, page_id))
  end
  @supplier_name = Parsing::Standard::StringField.new(
    prediction['supplier_name'],
    page_id
  )
  @supplier_phone_number = Parsing::Standard::StringField.new(
    prediction['supplier_phone_number'],
    page_id
  )
  @taxes = Parsing::Standard::Taxes.new(prediction['taxes'], page_id)
  @time = Parsing::Standard::StringField.new(prediction['time'], page_id)
  @tip = Parsing::Standard::AmountField.new(prediction['tip'], page_id)
  @total_amount = Parsing::Standard::AmountField.new(
    prediction['total_amount'],
    page_id
  )
  @total_net = Parsing::Standard::AmountField.new(
    prediction['total_net'],
    page_id
  )
  @total_tax = Parsing::Standard::AmountField.new(
    prediction['total_tax'],
    page_id
  )
end

Instance Attribute Details

#categoryMindee::V1::Parsing::Standard::ClassificationField (readonly)

The purchase category of the receipt.

Returns:



16
17
18
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 16

def category
  @category
end

#dateMindee::V1::Parsing::Standard::DateField (readonly)

The date the purchase was made.

Returns:



19
20
21
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 19

def date
  @date
end

#document_typeMindee::V1::Parsing::Standard::ClassificationField (readonly)

The type of receipt: EXPENSE RECEIPT or CREDIT CARD RECEIPT.

Returns:



22
23
24
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 22

def document_type
  @document_type
end

#line_itemsMindee::V1::Product::Receipt::ReceiptV5LineItems (readonly)

List of all line items on the receipt.

Returns:



25
26
27
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 25

def line_items
  @line_items
end

#localeMindee::V1::Parsing::Standard::LocaleField (readonly)

The locale of the document.

Returns:



28
29
30
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 28

def locale
  @locale
end

#receipt_numberMindee::V1::Parsing::Standard::StringField (readonly)

The receipt number or identifier.

Returns:



31
32
33
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 31

def receipt_number
  @receipt_number
end

#subcategoryMindee::V1::Parsing::Standard::ClassificationField (readonly)

The purchase subcategory of the receipt for transport and food.

Returns:



34
35
36
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 34

def subcategory
  @subcategory
end

#supplier_addressMindee::V1::Parsing::Standard::StringField (readonly)

The address of the supplier or merchant.

Returns:



37
38
39
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 37

def supplier_address
  @supplier_address
end

#supplier_company_registrationsArray<Mindee::V1::Parsing::Standard::CompanyRegistrationField> (readonly)

List of company registration numbers associated to the supplier.

Returns:



40
41
42
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 40

def supplier_company_registrations
  @supplier_company_registrations
end

#supplier_nameMindee::V1::Parsing::Standard::StringField (readonly)

The name of the supplier or merchant.

Returns:



43
44
45
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 43

def supplier_name
  @supplier_name
end

#supplier_phone_numberMindee::V1::Parsing::Standard::StringField (readonly)

The phone number of the supplier or merchant.

Returns:



46
47
48
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 46

def supplier_phone_number
  @supplier_phone_number
end

#taxesMindee::V1::Parsing::Standard::Taxes (readonly)

The list of taxes present on the receipt.

Returns:



49
50
51
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 49

def taxes
  @taxes
end

#timeMindee::V1::Parsing::Standard::StringField (readonly)

The time the purchase was made.

Returns:



52
53
54
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 52

def time
  @time
end

#tipMindee::V1::Parsing::Standard::AmountField (readonly)

The total amount of tip and gratuity.

Returns:



55
56
57
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 55

def tip
  @tip
end

#total_amountMindee::V1::Parsing::Standard::AmountField (readonly)

The total amount paid: includes taxes, discounts, fees, tips, and gratuity.

Returns:



58
59
60
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 58

def total_amount
  @total_amount
end

#total_netMindee::V1::Parsing::Standard::AmountField (readonly)

The net amount paid: does not include taxes, fees, and discounts.

Returns:



61
62
63
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 61

def total_net
  @total_net
end

#total_taxMindee::V1::Parsing::Standard::AmountField (readonly)

The sum of all taxes.

Returns:



64
65
66
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 64

def total_tax
  @total_tax
end

Instance Method Details

#line_items_separator(char) ⇒ String

Parameters:

Returns:



155
156
157
158
159
160
161
162
163
164
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 155

def line_items_separator(char)
  out_str = String.new
  out_str << '  '
  out_str << "+#{char * 38}"
  out_str << "+#{char * 10}"
  out_str << "+#{char * 14}"
  out_str << "+#{char * 12}"
  out_str << '+'
  out_str
end

#line_items_to_sString

Returns:



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 167

def line_items_to_s
  return '' if @line_items.empty?

  line_items = @line_items.map(&:to_table_line).join("\n#{line_items_separator('-')}\n  ")
  out_str = String.new
  out_str << "\n#{line_items_separator('-')}"
  out_str << "\n  |"
  out_str << ' Description                          |'
  out_str << ' Quantity |'
  out_str << ' Total Amount |'
  out_str << ' Unit Price |'
  out_str << "\n#{line_items_separator('=')}"
  out_str << "\n  #{line_items}"
  out_str << "\n#{line_items_separator('-')}"
  out_str
end

#to_sString

Returns:



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/mindee/v1/product/receipt/receipt_v5_document.rb', line 126

def to_s
  supplier_company_registrations = @supplier_company_registrations.join("\n #{' ' * 32}")
  line_items = line_items_to_s
  out_str = String.new
  out_str << "\n:Expense Locale: #{@locale}".rstrip
  out_str << "\n:Purchase Category: #{@category}".rstrip
  out_str << "\n:Purchase Subcategory: #{@subcategory}".rstrip
  out_str << "\n:Document Type: #{@document_type}".rstrip
  out_str << "\n:Purchase Date: #{@date}".rstrip
  out_str << "\n:Purchase Time: #{@time}".rstrip
  out_str << "\n:Total Amount: #{@total_amount}".rstrip
  out_str << "\n:Total Net: #{@total_net}".rstrip
  out_str << "\n:Total Tax: #{@total_tax}".rstrip
  out_str << "\n:Tip and Gratuity: #{@tip}".rstrip
  out_str << "\n:Taxes:#{@taxes}".rstrip
  out_str << "\n:Supplier Name: #{@supplier_name}".rstrip
  out_str << "\n:Supplier Company Registrations: #{supplier_company_registrations}".rstrip
  out_str << "\n:Supplier Address: #{@supplier_address}".rstrip
  out_str << "\n:Supplier Phone Number: #{@supplier_phone_number}".rstrip
  out_str << "\n:Receipt Number: #{@receipt_number}".rstrip
  out_str << "\n:Line Items:"
  out_str << line_items
  out_str[1..].to_s
end