diff --git a/docs/global_products/financial_document_v1.md b/docs/global_products/financial_document_v1.md index 0d1dabddc..843c4f93f 100644 --- a/docs/global_products/financial_document_v1.md +++ b/docs/global_products/financial_document_v1.md @@ -224,6 +224,21 @@ A typical `Field` object will have the following attributes: Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string. +### AddressField +Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following: + +* **street_number** (`String`): String representation of the street number. Can be `nil`. +* **street_name** (`String`): Name of the street. Can be `nil`. +* **po_box** (`String`): String representation of the PO Box number. Can be `nil`. +* **address_complement** (`String`): Address complement. Can be `nil`. +* **city** (`String`): City name. Can be `nil`. +* **postal_code** (`String`): String representation of the postal code. Can be `nil`. +* **state** (`String`): State name. Can be `nil`. +* **country** (`String`): Country name. Can be `nil`. + +Note: The `value` field of an AddressField should be a concatenation of the rest of the values. + + ### Amount Field The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`). @@ -304,7 +319,7 @@ A `FinancialDocumentV1LineItem` implements the following attributes: The following fields are extracted for Financial Document V1: ## Billing Address -**billing_address** ([StringField](#string-field)): The customer's address used for billing. +**billing_address** ([AddressField](#address-field)): The customer's address used for billing. ```rb puts result.document.inference.prediction.billing_address.value @@ -331,7 +346,7 @@ puts result.document.inference.prediction.category.value ``` ## Customer Address -**customer_address** ([StringField](#string-field)): The address of the customer. +**customer_address** ([AddressField](#address-field)): The address of the customer. ```rb puts result.document.inference.prediction.customer_address.value @@ -466,7 +481,7 @@ end ``` ## Shipping Address -**shipping_address** ([StringField](#string-field)): The customer's address used for shipping. +**shipping_address** ([AddressField](#address-field)): The customer's address used for shipping. ```rb puts result.document.inference.prediction.shipping_address.value @@ -497,7 +512,7 @@ puts result.document.inference.prediction.subcategory.value ``` ## Supplier Address -**supplier_address** ([StringField](#string-field)): The address of the supplier or merchant. +**supplier_address** ([AddressField](#address-field)): The address of the supplier or merchant. ```rb puts result.document.inference.prediction.supplier_address.value diff --git a/docs/global_products/invoices_v4.md b/docs/global_products/invoices_v4.md index 5d98a95e0..3d6d794d5 100644 --- a/docs/global_products/invoices_v4.md +++ b/docs/global_products/invoices_v4.md @@ -216,6 +216,21 @@ A typical `Field` object will have the following attributes: Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string. +### AddressField +Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following: + +* **street_number** (`String`): String representation of the street number. Can be `nil`. +* **street_name** (`String`): Name of the street. Can be `nil`. +* **po_box** (`String`): String representation of the PO Box number. Can be `nil`. +* **address_complement** (`String`): Address complement. Can be `nil`. +* **city** (`String`): City name. Can be `nil`. +* **postal_code** (`String`): String representation of the postal code. Can be `nil`. +* **state** (`String`): State name. Can be `nil`. +* **country** (`String`): Country name. Can be `nil`. + +Note: The `value` field of an AddressField should be a concatenation of the rest of the values. + + ### Amount Field The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`). @@ -296,7 +311,7 @@ A `InvoiceV4LineItem` implements the following attributes: The following fields are extracted for Invoice V4: ## Billing Address -**billing_address** ([StringField](#string-field)): The customer billing address. +**billing_address** ([AddressField](#address-field)): The customer billing address. ```rb puts result.document.inference.prediction.billing_address.value @@ -322,7 +337,7 @@ puts result.document.inference.prediction.category.value ``` ## Customer Address -**customer_address** ([StringField](#string-field)): The address of the customer. +**customer_address** ([AddressField](#address-field)): The address of the customer. ```rb puts result.document.inference.prediction.customer_address.value @@ -441,7 +456,7 @@ end ``` ## Shipping Address -**shipping_address** ([StringField](#string-field)): Customer's delivery address. +**shipping_address** ([AddressField](#address-field)): Customer's delivery address. ```rb puts result.document.inference.prediction.shipping_address.value @@ -472,7 +487,7 @@ puts result.document.inference.prediction.subcategory.value ``` ## Supplier Address -**supplier_address** ([StringField](#string-field)): The address of the supplier or merchant. +**supplier_address** ([AddressField](#address-field)): The address of the supplier or merchant. ```rb puts result.document.inference.prediction.supplier_address.value diff --git a/lib/mindee/parsing/standard.rb b/lib/mindee/parsing/standard.rb index e8f0406e5..c5a230b8c 100644 --- a/lib/mindee/parsing/standard.rb +++ b/lib/mindee/parsing/standard.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require_relative 'standard/address_field' require_relative 'standard/amount_field' require_relative 'standard/base_field' require_relative 'standard/boolean_field' diff --git a/lib/mindee/parsing/standard/address_field.rb b/lib/mindee/parsing/standard/address_field.rb new file mode 100644 index 000000000..c33f90e39 --- /dev/null +++ b/lib/mindee/parsing/standard/address_field.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require_relative 'string_field' + +module Mindee + module Parsing + module Standard + # Represents physical-address information. + class AddressField < Mindee::Parsing::Standard::StringField + # Street number + # @return [String, nil] + attr_reader :street_number + # Street name + # @return [String, nil] + attr_reader :street_name + # PO Box number + # @return [String, nil] + attr_reader :po_box + # Address complement + # @return [String, nil] + attr_reader :address_complement + # City name. + # @return [String, nil] + attr_reader :city + # Postal or ZIP code. + # @return [String, nil] + attr_reader :postal_code + # State, province or region. + # @return [String, nil] + attr_reader :state + # Country. + # @return [String, nil] + attr_reader :country + + def initialize(prediction, page_id = nil, reconstructed: false) + super + @street_number = prediction['street_number'] + @street_name = prediction['street_name'] + @po_box = prediction['po_box'] + @address_complement = prediction['address_complement'] + @city = prediction['city'] + @postal_code = prediction['postal_code'] + @state = prediction['state'] + @country = prediction['country'] + end + end + end + end +end diff --git a/lib/mindee/product/financial_document/financial_document_v1_document.rb b/lib/mindee/product/financial_document/financial_document_v1_document.rb index 600534b97..0a86d1b85 100644 --- a/lib/mindee/product/financial_document/financial_document_v1_document.rb +++ b/lib/mindee/product/financial_document/financial_document_v1_document.rb @@ -10,13 +10,13 @@ module FinancialDocument class FinancialDocumentV1Document < Mindee::Parsing::Common::Prediction include Mindee::Parsing::Standard # The customer's address used for billing. - # @return [Mindee::Parsing::Standard::StringField] + # @return [Mindee::Parsing::Standard::AddressField] attr_reader :billing_address # The purchase category. # @return [Mindee::Parsing::Standard::ClassificationField] attr_reader :category # The address of the customer. - # @return [Mindee::Parsing::Standard::StringField] + # @return [Mindee::Parsing::Standard::AddressField] attr_reader :customer_address # List of company registration numbers associated to the customer. # @return [Array] @@ -65,13 +65,13 @@ class FinancialDocumentV1Document < Mindee::Parsing::Common::Prediction # @return [Array] attr_reader :reference_numbers # The customer's address used for shipping. - # @return [Mindee::Parsing::Standard::StringField] + # @return [Mindee::Parsing::Standard::AddressField] attr_reader :shipping_address # The purchase subcategory for transport, food and shooping. # @return [Mindee::Parsing::Standard::ClassificationField] attr_reader :subcategory # The address of the supplier or merchant. - # @return [Mindee::Parsing::Standard::StringField] + # @return [Mindee::Parsing::Standard::AddressField] attr_reader :supplier_address # List of company registration numbers associated to the supplier. # @return [Array] @@ -114,7 +114,7 @@ class FinancialDocumentV1Document < Mindee::Parsing::Common::Prediction # @param page_id [Integer, nil] def initialize(prediction, page_id) super - @billing_address = Parsing::Standard::StringField.new( + @billing_address = Parsing::Standard::AddressField.new( prediction['billing_address'], page_id ) @@ -122,7 +122,7 @@ def initialize(prediction, page_id) prediction['category'], page_id ) - @customer_address = Parsing::Standard::StringField.new( + @customer_address = Parsing::Standard::AddressField.new( prediction['customer_address'], page_id ) @@ -182,7 +182,7 @@ def initialize(prediction, page_id) prediction['reference_numbers'].each do |item| @reference_numbers.push(Parsing::Standard::StringField.new(item, page_id)) end - @shipping_address = Parsing::Standard::StringField.new( + @shipping_address = Parsing::Standard::AddressField.new( prediction['shipping_address'], page_id ) @@ -190,7 +190,7 @@ def initialize(prediction, page_id) prediction['subcategory'], page_id ) - @supplier_address = Parsing::Standard::StringField.new( + @supplier_address = Parsing::Standard::AddressField.new( prediction['supplier_address'], page_id ) diff --git a/lib/mindee/product/invoice/invoice_v4_document.rb b/lib/mindee/product/invoice/invoice_v4_document.rb index 82344b6e4..9d4f1f044 100644 --- a/lib/mindee/product/invoice/invoice_v4_document.rb +++ b/lib/mindee/product/invoice/invoice_v4_document.rb @@ -10,13 +10,13 @@ module Invoice class InvoiceV4Document < Mindee::Parsing::Common::Prediction include Mindee::Parsing::Standard # The customer billing address. - # @return [Mindee::Parsing::Standard::StringField] + # @return [Mindee::Parsing::Standard::AddressField] attr_reader :billing_address # The purchase category. # @return [Mindee::Parsing::Standard::ClassificationField] attr_reader :category # The address of the customer. - # @return [Mindee::Parsing::Standard::StringField] + # @return [Mindee::Parsing::Standard::AddressField] attr_reader :customer_address # List of company registration numbers associated to the customer. # @return [Array] @@ -58,13 +58,13 @@ class InvoiceV4Document < Mindee::Parsing::Common::Prediction # @return [Array] attr_reader :reference_numbers # Customer's delivery address. - # @return [Mindee::Parsing::Standard::StringField] + # @return [Mindee::Parsing::Standard::AddressField] attr_reader :shipping_address # The purchase subcategory for transport, food and shopping. # @return [Mindee::Parsing::Standard::ClassificationField] attr_reader :subcategory # The address of the supplier or merchant. - # @return [Mindee::Parsing::Standard::StringField] + # @return [Mindee::Parsing::Standard::AddressField] attr_reader :supplier_address # List of company registration numbers associated to the supplier. # @return [Array] @@ -101,7 +101,7 @@ class InvoiceV4Document < Mindee::Parsing::Common::Prediction # @param page_id [Integer, nil] def initialize(prediction, page_id) super - @billing_address = Parsing::Standard::StringField.new( + @billing_address = Parsing::Standard::AddressField.new( prediction['billing_address'], page_id ) @@ -109,7 +109,7 @@ def initialize(prediction, page_id) prediction['category'], page_id ) - @customer_address = Parsing::Standard::StringField.new( + @customer_address = Parsing::Standard::AddressField.new( prediction['customer_address'], page_id ) @@ -159,7 +159,7 @@ def initialize(prediction, page_id) prediction['reference_numbers'].each do |item| @reference_numbers.push(Parsing::Standard::StringField.new(item, page_id)) end - @shipping_address = Parsing::Standard::StringField.new( + @shipping_address = Parsing::Standard::AddressField.new( prediction['shipping_address'], page_id ) @@ -167,7 +167,7 @@ def initialize(prediction, page_id) prediction['subcategory'], page_id ) - @supplier_address = Parsing::Standard::StringField.new( + @supplier_address = Parsing::Standard::AddressField.new( prediction['supplier_address'], page_id ) diff --git a/sig/mindee/parsing/standard/address_field.rbs b/sig/mindee/parsing/standard/address_field.rbs new file mode 100644 index 000000000..e1d9e493e --- /dev/null +++ b/sig/mindee/parsing/standard/address_field.rbs @@ -0,0 +1,18 @@ +# lib/mindee/parsing/standard/address_field.rb +module Mindee + module Parsing + module Standard + class AddressField < StringField + def street_number: -> String + def street_name: -> String + def po_box: -> String + def address_complement: -> String + def city: -> String + def postal_code: -> String + def state: -> String + def country: -> String + def initialize: (Hash[Symbol | String, untyped], ?Integer?, ?reconstructed: bool) -> void + end + end + end +end diff --git a/sig/mindee/product/financial_document/financial_document_v1_document.rbs b/sig/mindee/product/financial_document/financial_document_v1_document.rbs index 7e58ab0cc..b9fca7764 100644 --- a/sig/mindee/product/financial_document/financial_document_v1_document.rbs +++ b/sig/mindee/product/financial_document/financial_document_v1_document.rbs @@ -5,9 +5,9 @@ module Mindee module FinancialDocument class FinancialDocumentV1Document < Parsing::Common::Prediction def initialize: (Hash[Symbol | String, untyped], Integer?) -> void - def billing_address: -> (Parsing::Standard::StringField) + def billing_address: -> (Parsing::Standard::AddressField) def category: -> (Parsing::Standard::ClassificationField) - def customer_address: -> (Parsing::Standard::StringField) + def customer_address: -> (Parsing::Standard::AddressField) def customer_company_registrations: -> (Array[Parsing::Standard::CompanyRegistrationField]) def customer_id: -> (Parsing::Standard::StringField) def customer_name: -> (Parsing::Standard::StringField) @@ -23,9 +23,9 @@ module Mindee def po_number: -> (Parsing::Standard::StringField) def receipt_number: -> (Parsing::Standard::StringField) def reference_numbers: -> (Array[Parsing::Standard::StringField]) - def shipping_address: -> (Parsing::Standard::StringField) + def shipping_address: -> (Parsing::Standard::AddressField) def subcategory: -> (Parsing::Standard::ClassificationField) - def supplier_address: -> (Parsing::Standard::StringField) + def supplier_address: -> (Parsing::Standard::AddressField) def supplier_company_registrations: -> (Array[Parsing::Standard::CompanyRegistrationField]) def supplier_email: -> (Parsing::Standard::StringField) def supplier_name: -> (Parsing::Standard::StringField) diff --git a/sig/mindee/product/invoice/invoice_v4_document.rbs b/sig/mindee/product/invoice/invoice_v4_document.rbs index 6aa2feb32..78823fc07 100644 --- a/sig/mindee/product/invoice/invoice_v4_document.rbs +++ b/sig/mindee/product/invoice/invoice_v4_document.rbs @@ -5,9 +5,9 @@ module Mindee module Invoice class InvoiceV4Document < Parsing::Common::Prediction def initialize: (Hash[Symbol | String, untyped], Integer?) -> void - def billing_address: -> (Parsing::Standard::StringField) + def billing_address: -> (Parsing::Standard::AddressField) def category: -> (Parsing::Standard::ClassificationField) - def customer_address: -> (Parsing::Standard::StringField) + def customer_address: -> (Parsing::Standard::AddressField) def customer_company_registrations: -> (Array[Parsing::Standard::CompanyRegistrationField]) def customer_id: -> (Parsing::Standard::StringField) def customer_name: -> (Parsing::Standard::StringField) @@ -21,9 +21,9 @@ module Mindee def payment_date: -> (Parsing::Standard::DateField) def po_number: -> (Parsing::Standard::StringField) def reference_numbers: -> (Array[Parsing::Standard::StringField]) - def shipping_address: -> (Parsing::Standard::StringField) + def shipping_address: -> (Parsing::Standard::AddressField) def subcategory: -> (Parsing::Standard::ClassificationField) - def supplier_address: -> (Parsing::Standard::StringField) + def supplier_address: -> (Parsing::Standard::AddressField) def supplier_company_registrations: -> (Array[Parsing::Standard::CompanyRegistrationField]) def supplier_email: -> (Parsing::Standard::StringField) def supplier_name: -> (Parsing::Standard::StringField)