Class: Mindee::Product::Receipt::ReceiptV5LineItem
- Inherits:
-
Mindee::Parsing::Standard::FeatureField
- Object
- Mindee::Parsing::Standard::AbstractField
- Mindee::Parsing::Standard::FeatureField
- Mindee::Product::Receipt::ReceiptV5LineItem
- 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
-
#description ⇒ String
readonly
The item description.
-
#quantity ⇒ Float
readonly
The item quantity.
-
#total_amount ⇒ Float
readonly
The item total amount.
-
#unit_price ⇒ Float
readonly
The item unit price.
Attributes inherited from Mindee::Parsing::Standard::AbstractField
#bounding_box, #confidence, #page_id, #polygon
Instance Method Summary collapse
-
#initialize(prediction, page_id) ⇒ ReceiptV5LineItem
constructor
A new instance of ReceiptV5LineItem.
- #printable_values ⇒ Hash
- #table_printable_values ⇒ Hash
- #to_s ⇒ String
- #to_table_line ⇒ String
Methods inherited from Mindee::Parsing::Standard::FeatureField
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.
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
#description ⇒ String (readonly)
The item description.
13 14 15 |
# File 'lib/mindee/product/receipt/receipt_v5_line_item.rb', line 13 def description @description end |
#quantity ⇒ Float (readonly)
The item quantity.
16 17 18 |
# File 'lib/mindee/product/receipt/receipt_v5_line_item.rb', line 16 def quantity @quantity end |
#total_amount ⇒ Float (readonly)
The item total amount.
19 20 21 |
# File 'lib/mindee/product/receipt/receipt_v5_line_item.rb', line 19 def total_amount @total_amount end |
#unit_price ⇒ Float (readonly)
The item unit price.
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_values ⇒ 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_values ⇒ 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_s ⇒ 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_line ⇒ 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 |