Class: Ticketbai::TbaiIdentifier

Inherits:
Object
  • Object
show all
Defined in:
lib/ticketbai/tbai_identifier.rb

Constant Summary collapse

ID =
'TBAI'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ TbaiIdentifier

Returns a new instance of TbaiIdentifier.

Parameters:

  • nif (String)

    The issuer NIF

  • invoice_date (String)

    Format DDMMYY

  • signature_value (String)

    First 13 characters of the signatureValue present in the signed xml



12
13
14
15
16
# File 'lib/ticketbai/tbai_identifier.rb', line 12

def initialize(**args)
  self.nif = args[:nif]
  self.invoice_date = args[:invoice_date]
  self.signature_value = args[:signature_value][0..12]
end

Instance Attribute Details

#invoice_dateObject

Returns the value of attribute invoice_date.



5
6
7
# File 'lib/ticketbai/tbai_identifier.rb', line 5

def invoice_date
  @invoice_date
end

#nifObject

Returns the value of attribute nif.



5
6
7
# File 'lib/ticketbai/tbai_identifier.rb', line 5

def nif
  @nif
end

#signature_valueObject

Returns the value of attribute signature_value.



5
6
7
# File 'lib/ticketbai/tbai_identifier.rb', line 5

def signature_value
  @signature_value
end

Instance Method Details

#createString

Builds the TBAI Identifier with the following format: TBAI-NIF-FechaExpedicionFactura(DDMMAA)-SignatureValue(13)-CRC(3)

Returns:

  • (String)

    The TBAI identifier.



22
23
24
25
26
27
28
29
30
31
# File 'lib/ticketbai/tbai_identifier.rb', line 22

def create
  identifier = [ID, @nif, @invoice_date, @signature_value].join('-')
  identifier << '-'

  crc = ChecksumCalculator.new(identifier).calculate

  identifier << crc

  identifier
end