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

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

Overview

Receipt API version 5.3 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:

  • prediction (Hash)
  • page_id (Integer, nil)


66
67
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
# File 'lib/mindee/product/receipt/receipt_v5_document.rb', line 66

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::Parsing::Standard::ClassificationField (readonly)

The purchase category of the receipt.



14
15
16
# File 'lib/mindee/product/receipt/receipt_v5_document.rb', line 14

def category
  @category
end

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

The date the purchase was made.



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

def date
  @date
end

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

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



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

def document_type
  @document_type
end

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

List of all line items on the receipt.



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

def line_items
  @line_items
end

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

The locale of the document.



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

def locale
  @locale
end

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

The receipt number or identifier.



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

def receipt_number
  @receipt_number
end

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

The purchase subcategory of the receipt for transport and food.



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

def subcategory
  @subcategory
end

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

The address of the supplier or merchant.



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

def supplier_address
  @supplier_address
end

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

List of company registration numbers associated to the supplier.



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

def supplier_company_registrations
  @supplier_company_registrations
end

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

The name of the supplier or merchant.



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

def supplier_name
  @supplier_name
end

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

The phone number of the supplier or merchant.



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

def supplier_phone_number
  @supplier_phone_number
end

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

The list of taxes present on the receipt.



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

def taxes
  @taxes
end

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

The time the purchase was made.



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

def time
  @time
end

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

The total amount of tip and gratuity.



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

def tip
  @tip
end

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

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



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

def total_amount
  @total_amount
end

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

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



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

def total_net
  @total_net
end

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

The sum of all taxes.



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

def total_tax
  @total_tax
end

Instance Method Details

#to_sString

Returns:

  • (String)


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

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