Class: Mindee::Product::Receipt::ReceiptV5LineItem

Inherits:
Mindee::Parsing::Standard::FeatureField show all
Includes:
Mindee::Parsing::Standard
Defined in:
lib/mindee/product/receipt/receipt_v5_line_item.rb

Overview

List of line item details.

Instance Attribute Summary collapse

Attributes inherited from Mindee::Parsing::Standard::AbstractField

#bounding_box, #confidence, #page_id, #polygon

Instance Method Summary collapse

Methods inherited from Mindee::Parsing::Standard::FeatureField

#format_for_display

Methods inherited from Mindee::Parsing::Standard::AbstractField

array_confidence, array_sum, float_to_string

Constructor Details

#initialize(prediction, page_id) ⇒ ReceiptV5LineItem

Returns a new instance of ReceiptV5LineItem.

Parameters:

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


26
27
28
29
30
31
32
33
# File 'lib/mindee/product/receipt/receipt_v5_line_item.rb', line 26

def initialize(prediction, page_id)
  super(prediction, page_id)
  @description = prediction['description']
  @quantity = prediction['quantity']
  @total_amount = prediction['total_amount']
  @unit_price = prediction['unit_price']
  @page_id = page_id
end

Instance Attribute Details

#descriptionString (readonly)

The item description.

Returns:

  • (String)


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

def description
  @description
end

#quantityFloat (readonly)

The item quantity.

Returns:

  • (Float)


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

def quantity
  @quantity
end

#total_amountFloat (readonly)

The item total amount.

Returns:

  • (Float)


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

def total_amount
  @total_amount
end

#unit_priceFloat (readonly)

The item unit price.

Returns:

  • (Float)


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

def unit_price
  @unit_price
end

Instance Method Details

#printable_valuesHash

Returns:

  • (Hash)


36
37
38
39
40
41
42
43
# File 'lib/mindee/product/receipt/receipt_v5_line_item.rb', line 36

def printable_values
  printable = {}
  printable[:description] = format_for_display(@description)
  printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity)
  printable[:total_amount] = @total_amount.nil? ? '' : Field.float_to_string(@total_amount)
  printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price)
  printable
end

#table_printable_valuesHash

Returns:

  • (Hash)


46
47
48
49
50
51
52
53
# File 'lib/mindee/product/receipt/receipt_v5_line_item.rb', line 46

def table_printable_values
  printable = {}
  printable[:description] = format_for_display(@description, 36)
  printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity)
  printable[:total_amount] = @total_amount.nil? ? '' : Field.float_to_string(@total_amount)
  printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price)
  printable
end

#to_sString

Returns:

  • (String)


67
68
69
70
71
72
73
74
75
# File 'lib/mindee/product/receipt/receipt_v5_line_item.rb', line 67

def to_s
  printable = printable_values
  out_str = String.new
  out_str << "\n  :Description: #{printable[:description]}"
  out_str << "\n  :Quantity: #{printable[:quantity]}"
  out_str << "\n  :Total Amount: #{printable[:total_amount]}"
  out_str << "\n  :Unit Price: #{printable[:unit_price]}"
  out_str
end

#to_table_lineString

Returns:

  • (String)


56
57
58
59
60
61
62
63
64
# File 'lib/mindee/product/receipt/receipt_v5_line_item.rb', line 56

def to_table_line
  printable = table_printable_values
  out_str = String.new
  out_str << format('| %- 37s', printable[:description])
  out_str << format('| %- 9s', printable[:quantity])
  out_str << format('| %- 13s', printable[:total_amount])
  out_str << format('| %- 11s', printable[:unit_price])
  out_str << '|'
end