Class: Nfe::ServiceInvoiceBorrower

Inherits:
Data
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServiceInvoiceBorrower

Returns a new instance of ServiceInvoiceBorrower.

Parameters:

  • id: (String, nil)
  • name: (String, nil)
  • federal_tax_number: (String, nil)
  • email: (String, nil)
  • phone_number: (String, nil)
  • address: (Object)
  • parent_id: (String, nil)
  • raw: (Hash[untyped, untyped], nil)


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

#addressObject (readonly)

Returns the value of attribute address.

Returns:

  • (Object)


8
9
10
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 8

def address
  @address
end

#emailString? (readonly)

Returns the value of attribute email.

Returns:

  • (String, nil)


6
7
8
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 6

def email
  @email
end

#federal_tax_numberString? (readonly)

Returns the value of attribute federal_tax_number.

Returns:

  • (String, nil)


5
6
7
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 5

def federal_tax_number
  @federal_tax_number
end

#idString? (readonly)

Returns the value of attribute id.

Returns:

  • (String, nil)


3
4
5
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 3

def id
  @id
end

#nameString? (readonly)

Returns the value of attribute name.

Returns:

  • (String, nil)


4
5
6
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 4

def name
  @name
end

#parent_idString? (readonly)

Returns the value of attribute parent_id.

Returns:

  • (String, nil)


9
10
11
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 9

def parent_id
  @parent_id
end

#phone_numberString? (readonly)

Returns the value of attribute phone_number.

Returns:

  • (String, nil)


7
8
9
# File 'sig/nfe/resources/dto/service_invoice_borrower.rbs', line 7

def phone_number
  @phone_number
end

#rawHash[untyped, untyped]? (readonly)

Returns the value of attribute raw.

Returns:

  • (Hash[untyped, untyped], nil)


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.

Parameters:

  • payload (Hash, nil)

    the borrower object from the wire.

Returns:



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

.newinstance

Parameters:

  • id: (String, nil)
  • name: (String, nil)
  • federal_tax_number: (String, nil)
  • email: (String, nil)
  • phone_number: (String, nil)
  • address: (Object)
  • parent_id: (String, nil)
  • raw: (Hash[untyped, untyped], nil)

Returns:

  • (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.

Parameters:

  • key (Object)

Returns:

  • (Object)


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").

Parameters:

  • keys (Object)

Returns:

  • (Object)


55
56
57
# File 'lib/nfe/resources/dto/service_invoice_borrower.rb', line 55

def dig(*keys)
  raw&.dig(*keys)
end