Class: Mindee::Product::Invoice::InvoiceV4LineItem

Inherits:
Mindee::Parsing::Standard::FeatureField show all
Includes:
Mindee::Parsing::Standard
Defined in:
lib/mindee/product/invoice/invoice_v4_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) ⇒ InvoiceV4LineItem

Returns a new instance of InvoiceV4LineItem.

Parameters:

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


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mindee/product/invoice/invoice_v4_line_item.rb', line 38

def initialize(prediction, page_id)
  super(prediction, page_id)
  @description = prediction['description']
  @product_code = prediction['product_code']
  @quantity = prediction['quantity']
  @tax_amount = prediction['tax_amount']
  @tax_rate = prediction['tax_rate']
  @total_amount = prediction['total_amount']
  @unit_measure = prediction['unit_measure']
  @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/invoice/invoice_v4_line_item.rb', line 13

def description
  @description
end

#product_codeString (readonly)

The product code referring to the item.

Returns:

  • (String)


16
17
18
# File 'lib/mindee/product/invoice/invoice_v4_line_item.rb', line 16

def product_code
  @product_code
end

#quantityFloat (readonly)

The item quantity

Returns:

  • (Float)


19
20
21
# File 'lib/mindee/product/invoice/invoice_v4_line_item.rb', line 19

def quantity
  @quantity
end

#tax_amountFloat (readonly)

The item tax amount.

Returns:

  • (Float)


22
23
24
# File 'lib/mindee/product/invoice/invoice_v4_line_item.rb', line 22

def tax_amount
  @tax_amount
end

#tax_rateFloat (readonly)

The item tax rate in percentage.

Returns:

  • (Float)


25
26
27
# File 'lib/mindee/product/invoice/invoice_v4_line_item.rb', line 25

def tax_rate
  @tax_rate
end

#total_amountFloat (readonly)

The item total amount.

Returns:

  • (Float)


28
29
30
# File 'lib/mindee/product/invoice/invoice_v4_line_item.rb', line 28

def total_amount
  @total_amount
end

#unit_measureString (readonly)

The item unit of measure.

Returns:

  • (String)


31
32
33
# File 'lib/mindee/product/invoice/invoice_v4_line_item.rb', line 31

def unit_measure
  @unit_measure
end

#unit_priceFloat (readonly)

The item unit price.

Returns:

  • (Float)


34
35
36
# File 'lib/mindee/product/invoice/invoice_v4_line_item.rb', line 34

def unit_price
  @unit_price
end

Instance Method Details

#printable_valuesHash

Returns:

  • (Hash)


52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/mindee/product/invoice/invoice_v4_line_item.rb', line 52

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

#table_printable_valuesHash

Returns:

  • (Hash)


66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/mindee/product/invoice/invoice_v4_line_item.rb', line 66

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

#to_sString

Returns:

  • (String)


95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/mindee/product/invoice/invoice_v4_line_item.rb', line 95

def to_s
  printable = printable_values
  out_str = String.new
  out_str << "\n  :Description: #{printable[:description]}"
  out_str << "\n  :Product code: #{printable[:product_code]}"
  out_str << "\n  :Quantity: #{printable[:quantity]}"
  out_str << "\n  :Tax Amount: #{printable[:tax_amount]}"
  out_str << "\n  :Tax Rate (%): #{printable[:tax_rate]}"
  out_str << "\n  :Total Amount: #{printable[:total_amount]}"
  out_str << "\n  :Unit of measure: #{printable[:unit_measure]}"
  out_str << "\n  :Unit Price: #{printable[:unit_price]}"
  out_str
end

#to_table_lineString

Returns:

  • (String)


80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mindee/product/invoice/invoice_v4_line_item.rb', line 80

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