Class: Ticketbai::ChecksumCalculator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ChecksumCalculator

Returns a new instance of ChecksumCalculator.



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

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/ticketbai/checksum_calculator.rb', line 3

def data
  @data
end

Instance Method Details

#calculateObject



9
10
11
12
13
# File 'lib/ticketbai/checksum_calculator.rb', line 9

def calculate
  checksum = Digest::CRC8.checksum(@data)

  format('%03d', checksum.to_s)
end