Class: Nfe::Company

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCompany

Returns a new instance of Company.

Parameters:

  • id: (String, nil)
  • name: (String, nil)
  • trade_name: (String, nil)
  • federal_tax_number: (String, nil)
  • email: (String, nil)
  • status: (Object)
  • tax_regime: (Object)
  • municipal_tax_number: (String, nil)
  • address: (Object)
  • state_taxes: (Object)
  • municipal_taxes: (Object)
  • environment: (Object)
  • account_id: (String, nil)
  • created_on: (String, nil)
  • modified_on: (String, nil)


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_idString? (readonly)

Returns the value of attribute account_id.

Returns:

  • (String, nil)


15
16
17
# File 'sig/nfe/resources/dto/company.rbs', line 15

def 
  @account_id
end

#addressObject (readonly)

Returns the value of attribute address.

Returns:

  • (Object)


11
12
13
# File 'sig/nfe/resources/dto/company.rbs', line 11

def address
  @address
end

#created_onString? (readonly)

Returns the value of attribute created_on.

Returns:

  • (String, nil)


16
17
18
# File 'sig/nfe/resources/dto/company.rbs', line 16

def created_on
  @created_on
end

#emailString? (readonly)

Returns the value of attribute email.

Returns:

  • (String, nil)


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

def email
  @email
end

#environmentObject (readonly)

Returns the value of attribute environment.

Returns:

  • (Object)


14
15
16
# File 'sig/nfe/resources/dto/company.rbs', line 14

def environment
  @environment
end

#federal_tax_numberString? (readonly)

Returns the value of attribute federal_tax_number.

Returns:

  • (String, nil)


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

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/company.rbs', line 3

def id
  @id
end

#modified_onString? (readonly)

Returns the value of attribute modified_on.

Returns:

  • (String, nil)


17
18
19
# File 'sig/nfe/resources/dto/company.rbs', line 17

def modified_on
  @modified_on
end

#municipal_tax_numberString? (readonly)

Returns the value of attribute municipal_tax_number.

Returns:

  • (String, nil)


10
11
12
# File 'sig/nfe/resources/dto/company.rbs', line 10

def municipal_tax_number
  @municipal_tax_number
end

#municipal_taxesObject (readonly)

Returns the value of attribute municipal_taxes.

Returns:

  • (Object)


13
14
15
# File 'sig/nfe/resources/dto/company.rbs', line 13

def municipal_taxes
  @municipal_taxes
end

#nameString? (readonly)

Returns the value of attribute name.

Returns:

  • (String, nil)


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

def name
  @name
end

#state_taxesObject (readonly)

Returns the value of attribute state_taxes.

Returns:

  • (Object)


12
13
14
# File 'sig/nfe/resources/dto/company.rbs', line 12

def state_taxes
  @state_taxes
end

#statusObject (readonly)

Returns the value of attribute status.

Returns:

  • (Object)


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

def status
  @status
end

#tax_regimeObject (readonly)

Returns the value of attribute tax_regime.

Returns:

  • (Object)


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

def tax_regime
  @tax_regime
end

#trade_nameString? (readonly)

Returns the value of attribute trade_name.

Returns:

  • (String, nil)


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.

Parameters:

  • payload (Hash, nil)

    the unwrapped company object.

Returns:



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

.newinstance

Parameters:

  • id: (String, nil)
  • name: (String, nil)
  • trade_name: (String, nil)
  • federal_tax_number: (String, nil)
  • email: (String, nil)
  • status: (Object)
  • tax_regime: (Object)
  • municipal_tax_number: (String, nil)
  • address: (Object)
  • state_taxes: (Object)
  • municipal_taxes: (Object)
  • environment: (Object)
  • account_id: (String, nil)
  • created_on: (String, nil)
  • modified_on: (String, nil)

Returns:

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

Parameters:

  • value (Object)

Returns:

  • (String, nil)


61
62
63
# File 'lib/nfe/resources/dto/company.rb', line 61

def self.stringify(value)
  value&.to_s
end