Method: AEMO::NMI#checksum

Defined in:
lib/aemo/nmi.rb

#checksumInteger

Checksum is a function to calculate the checksum value for a given National Meter Identifier

Returns:

  • (Integer)

    the checksum value for the current National Meter Identifier

Since:

  • 2014-12-05



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/aemo/nmi.rb', line 158

def checksum
  summation = 0
  @nmi.reverse.split(//).each_index do |i|
    value = nmi[nmi.length - i - 1].ord
    value *= 2 if i.even?
    value = value.to_s.split(//).map(&:to_i).reduce(:+)
    summation += value
  end
  checksum = (10 - (summation % 10)) % 10
  checksum
end