Class: Mindee::Product::Receipt::ReceiptV4Document

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

Overview

Expense Receipt V4 document prediction.

Direct Known Subclasses

ReceiptV4PagePrediction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prediction, page_id) ⇒ ReceiptV4Document

Returns a new instance of ReceiptV4Document.

Parameters:

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


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/mindee/product/receipt/receipt_v4_document.rb', line 50

def initialize(prediction, page_id)
  super()
  @locale = LocaleField.new(prediction['locale'])
  @total_amount = AmountField.new(prediction['total_amount'], page_id)
  @total_net = AmountField.new(prediction['total_net'], page_id)
  @total_tax = AmountField.new(prediction['total_tax'], page_id)
  @tip = AmountField.new(prediction['tip'], page_id)
  @date = DateField.new(prediction['date'], page_id)
  @category = ClassificationField.new(prediction['category'], page_id)
  @subcategory = ClassificationField.new(prediction['subcategory'], page_id)
  @document_type = ClassificationField.new(prediction['document_type'], page_id)
  @supplier = StringField.new(prediction['supplier'], page_id)
  @time = StringField.new(prediction['time'], page_id)
  @taxes = Taxes.new(prediction['taxes'], page_id)
end

Instance Attribute Details

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

The receipt category among predefined classes.



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

def category
  @category
end

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

The purchase date.



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

def date
  @date
end

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

Whether the document is an expense receipt or a credit card receipt.



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

def document_type
  @document_type
end

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

Where the purchase was made, the language, and the currency.



13
14
15
# File 'lib/mindee/product/receipt/receipt_v4_document.rb', line 13

def locale
  @locale
end

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

The receipt sub-category among predefined classes.



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

def subcategory
  @subcategory
end

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

The name of the supplier or merchant, as seen on the receipt.



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

def supplier
  @supplier
end

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

List of taxes detected on the receipt.



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

def taxes
  @taxes
end

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

Time as seen on the receipt in HH:MM format.



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

def time
  @time
end

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

Total amount of tip and gratuity. Both typed and handwritten characters are supported.



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

def tip
  @tip
end

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

Total including taxes



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

def total_amount
  @total_amount
end

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

Total amount of the purchase excluding taxes.



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

def total_net
  @total_net
end

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

Total tax amount of the purchase.



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

def total_tax
  @total_tax
end

Instance Method Details

#to_sString

Returns:

  • (String)


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/mindee/product/receipt/receipt_v4_document.rb', line 67

def to_s
  out_str = String.new
  out_str << "\n:Locale: #{@locale}".rstrip
  out_str << "\n:Date: #{@date}".rstrip
  out_str << "\n:Category: #{@category}".rstrip
  out_str << "\n:Subcategory: #{@subcategory}".rstrip
  out_str << "\n:Document type: #{@document_type}".rstrip
  out_str << "\n:Time: #{@time}".rstrip
  out_str << "\n:Supplier name: #{@supplier}".rstrip
  out_str << "\n:Taxes:#{@taxes}".rstrip
  out_str << "\n:Total net: #{@total_net}".rstrip
  out_str << "\n:Total tax: #{@total_tax}".rstrip
  out_str << "\n:Tip: #{@tip}".rstrip
  out_str << "\n:Total amount: #{@total_amount}".rstrip
  out_str[1..].to_s
end