Class: Nfe::ServiceInvoiceBorrower
- Inherits:
-
Data
- Object
- Data
- Nfe::ServiceInvoiceBorrower
- Defined in:
- lib/nfe/resources/dto/service_invoice_borrower.rb,
sig/nfe/resources/dto/service_invoice_borrower.rbs
Overview
Immutable value object for the borrower (tomador) of a service invoice,
as embedded in the NFS-e retrieve response (+nf-servico-v1.yaml+, inline
schema of GET /v1/companies/{company_id}/serviceinvoices/{id}).
federal_tax_number is normalized to String via Company.stringify:
the spec declares it integer int64, but the alphanumeric CNPJ
(IN RFB 2.229/2024) requires string tolerance — deliberate deviation,
pinned by the alignment test. address stays a raw Hash.
Hash-compatibility bridge: before this DTO existed, invoice.borrower
returned the raw wire Hash — #[] and #dig delegate to #raw so
borrower["name"] keeps working alongside the typed readers.
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#email ⇒ String?
readonly
Returns the value of attribute email.
-
#federal_tax_number ⇒ String?
readonly
Returns the value of attribute federal_tax_number.
-
#id ⇒ String?
readonly
Returns the value of attribute id.
-
#name ⇒ String?
readonly
Returns the value of attribute name.
-
#parent_id ⇒ String?
readonly
Returns the value of attribute parent_id.
-
#phone_number ⇒ String?
readonly
Returns the value of attribute phone_number.
-
#raw ⇒ Hash[untyped, untyped]?
readonly
Returns the value of attribute raw.
Class Method Summary collapse
-
.from_api(payload) ⇒ Nfe::ServiceInvoiceBorrower?
Build a ServiceInvoiceBorrower from an API payload.
- .new ⇒ instance
Instance Method Summary collapse
-
#[](key) ⇒ Object
Hash-style read, delegated to the raw wire payload (camelCase keys), e.g.
-
#dig(*keys) ⇒ Object
Hash-style nested read over the raw wire payload, e.g.
-
#initialize ⇒ ServiceInvoiceBorrower
constructor
A new instance of ServiceInvoiceBorrower.
Constructor Details
#initialize ⇒ ServiceInvoiceBorrower
Returns a new instance of ServiceInvoiceBorrower.
16 |
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 16
def initialize: (id: String?, name: String?, federal_tax_number: String?, email: String?, phone_number: String?, address: untyped, parent_id: String?, raw: Hash[untyped, untyped]?) -> void
|
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
8 9 10 |
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 8 def address @address end |
#email ⇒ String? (readonly)
Returns the value of attribute email.
6 7 8 |
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 6 def email @email end |
#federal_tax_number ⇒ String? (readonly)
Returns the value of attribute federal_tax_number.
5 6 7 |
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 5 def federal_tax_number @federal_tax_number end |
#id ⇒ String? (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 3 def id @id end |
#name ⇒ String? (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 4 def name @name end |
#parent_id ⇒ String? (readonly)
Returns the value of attribute parent_id.
9 10 11 |
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 9 def parent_id @parent_id end |
#phone_number ⇒ String? (readonly)
Returns the value of attribute phone_number.
7 8 9 |
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 7 def phone_number @phone_number end |
#raw ⇒ Hash[untyped, untyped]? (readonly)
Returns the value of attribute raw.
10 11 12 |
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 10 def raw @raw end |
Class Method Details
.from_api(payload) ⇒ Nfe::ServiceInvoiceBorrower?
Build a Nfe::ServiceInvoiceBorrower from an API payload.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nfe/resources/dto/service_invoice_borrower.rb', line 32 def self.from_api(payload) return nil if payload.nil? new( id: payload["id"], name: payload["name"], federal_tax_number: Company.stringify(payload["federalTaxNumber"]), email: payload["email"], phone_number: payload["phoneNumber"], address: payload["address"], parent_id: payload["parentId"], raw: payload ) end |
.new ⇒ instance
14 |
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 14
def self.new: (id: String?, name: String?, federal_tax_number: String?, email: String?, phone_number: String?, address: untyped, parent_id: String?, raw: Hash[untyped, untyped]?) -> instance
|
Instance Method Details
#[](key) ⇒ Object
Hash-style read, delegated to the raw wire payload (camelCase keys),
e.g. borrower["federalTaxNumber"] returns the wire value untouched.
49 50 51 |
# File 'lib/nfe/resources/dto/service_invoice_borrower.rb', line 49 def [](key) raw && raw[key] end |
#dig(*keys) ⇒ Object
Hash-style nested read over the raw wire payload,
e.g. borrower.dig("address", "city", "name").
55 56 57 |
# File 'lib/nfe/resources/dto/service_invoice_borrower.rb', line 55 def dig(*keys) raw&.dig(*keys) end |