Class: Nfe::Company
- Inherits:
-
Data
- Object
- Data
- Nfe::Company
- Defined in:
- lib/nfe/resources/dto/company.rb,
sig/nfe/resources/dto/company.rbs
Overview
Immutable value object for a company (emitente) as returned by the NFE.io
api.nfe.io/v1 entity API.
Hand-written (rather than reusing the mangled generated contribuintes_v2
DTOs) so the public shape stays clean and snake_case. Company.from_api maps the
API camelCase keys onto the snake_case members, drops unknown keys, and is
nil-tolerant (+from_api(nil)+ returns nil).
federal_tax_number is kept as a String — never coerced to Integer —
so future alphanumeric CNPJ (IN RFB 2.229/2024) is preserved.
Instance Attribute Summary collapse
-
#account_id ⇒ String?
readonly
Returns the value of attribute account_id.
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#created_on ⇒ String?
readonly
Returns the value of attribute created_on.
-
#email ⇒ String?
readonly
Returns the value of attribute email.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#federal_tax_number ⇒ String?
readonly
Returns the value of attribute federal_tax_number.
-
#id ⇒ String?
readonly
Returns the value of attribute id.
-
#modified_on ⇒ String?
readonly
Returns the value of attribute modified_on.
-
#municipal_tax_number ⇒ String?
readonly
Returns the value of attribute municipal_tax_number.
-
#municipal_taxes ⇒ Object
readonly
Returns the value of attribute municipal_taxes.
-
#name ⇒ String?
readonly
Returns the value of attribute name.
-
#state_taxes ⇒ Object
readonly
Returns the value of attribute state_taxes.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#tax_regime ⇒ Object
readonly
Returns the value of attribute tax_regime.
-
#trade_name ⇒ String?
readonly
Returns the value of attribute trade_name.
Class Method Summary collapse
-
.from_api(payload) ⇒ Nfe::Company?
Build a Company from an API payload.
- .new ⇒ instance
-
.stringify(value) ⇒ String?
private
Coerce a tax number to a
Stringwithout numeric coercion, preserving alphanumeric CNPJ.
Instance Method Summary collapse
-
#initialize ⇒ Company
constructor
A new instance of Company.
Constructor Details
#initialize ⇒ Company
Returns a new instance of Company.
25 |
# File 'sig/nfe/resources/dto/company.rbs', line 25
def initialize: (id: String?, name: String?, trade_name: String?, federal_tax_number: String?, email: String?, status: untyped, tax_regime: untyped, municipal_tax_number: String?, address: untyped, state_taxes: untyped, municipal_taxes: untyped, environment: untyped, account_id: String?, created_on: String?, modified_on: String?) -> void
|
Instance Attribute Details
#account_id ⇒ String? (readonly)
Returns the value of attribute account_id.
15 16 17 |
# File 'sig/nfe/resources/dto/company.rbs', line 15 def account_id @account_id end |
#address ⇒ Object (readonly)
Returns the value of attribute address.
11 12 13 |
# File 'sig/nfe/resources/dto/company.rbs', line 11 def address @address end |
#created_on ⇒ String? (readonly)
Returns the value of attribute created_on.
16 17 18 |
# File 'sig/nfe/resources/dto/company.rbs', line 16 def created_on @created_on end |
#email ⇒ String? (readonly)
Returns the value of attribute email.
7 8 9 |
# File 'sig/nfe/resources/dto/company.rbs', line 7 def email @email end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
14 15 16 |
# File 'sig/nfe/resources/dto/company.rbs', line 14 def environment @environment end |
#federal_tax_number ⇒ String? (readonly)
Returns the value of attribute federal_tax_number.
6 7 8 |
# File 'sig/nfe/resources/dto/company.rbs', line 6 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/company.rbs', line 3 def id @id end |
#modified_on ⇒ String? (readonly)
Returns the value of attribute modified_on.
17 18 19 |
# File 'sig/nfe/resources/dto/company.rbs', line 17 def modified_on @modified_on end |
#municipal_tax_number ⇒ String? (readonly)
Returns the value of attribute municipal_tax_number.
10 11 12 |
# File 'sig/nfe/resources/dto/company.rbs', line 10 def municipal_tax_number @municipal_tax_number end |
#municipal_taxes ⇒ Object (readonly)
Returns the value of attribute municipal_taxes.
13 14 15 |
# File 'sig/nfe/resources/dto/company.rbs', line 13 def municipal_taxes @municipal_taxes end |
#name ⇒ String? (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'sig/nfe/resources/dto/company.rbs', line 4 def name @name end |
#state_taxes ⇒ Object (readonly)
Returns the value of attribute state_taxes.
12 13 14 |
# File 'sig/nfe/resources/dto/company.rbs', line 12 def state_taxes @state_taxes end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'sig/nfe/resources/dto/company.rbs', line 8 def status @status end |
#tax_regime ⇒ Object (readonly)
Returns the value of attribute tax_regime.
9 10 11 |
# File 'sig/nfe/resources/dto/company.rbs', line 9 def tax_regime @tax_regime end |
#trade_name ⇒ String? (readonly)
Returns the value of attribute trade_name.
5 6 7 |
# File 'sig/nfe/resources/dto/company.rbs', line 5 def trade_name @trade_name end |
Class Method Details
.from_api(payload) ⇒ Nfe::Company?
Build a Nfe::Company from an API payload.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/nfe/resources/dto/company.rb', line 35 def self.from_api(payload) return nil if payload.nil? new( id: payload["id"], name: payload["name"], trade_name: payload["tradeName"], federal_tax_number: stringify(payload["federalTaxNumber"]), email: payload["email"], status: payload["status"], tax_regime: payload["taxRegime"], municipal_tax_number: payload["municipalTaxNumber"], address: payload["address"], state_taxes: payload["stateTaxes"], municipal_taxes: payload["municipalTaxes"], environment: payload["environment"], account_id: payload["accountId"], created_on: payload["createdOn"], modified_on: payload["modifiedOn"] ) end |
.new ⇒ instance
23 |
# File 'sig/nfe/resources/dto/company.rbs', line 23
def self.new: (id: String?, name: String?, trade_name: String?, federal_tax_number: String?, email: String?, status: untyped, tax_regime: untyped, municipal_tax_number: String?, address: untyped, state_taxes: untyped, municipal_taxes: untyped, environment: untyped, account_id: String?, created_on: String?, modified_on: String?) -> instance
|
.stringify(value) ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Coerce a tax number to a String without numeric coercion, preserving
alphanumeric CNPJ. nil stays nil.
61 62 63 |
# File 'lib/nfe/resources/dto/company.rb', line 61 def self.stringify(value) value&.to_s end |