Class: CzechPost::CodeGenerator::CheckDigit

Inherits:
Object
  • Object
show all
Defined in:
lib/czech_post/code_generator/check_digit.rb

Constant Summary collapse

DIGIT =

186_423_597

[1, 8, 6, 4, 2, 3, 5, 9, 7].freeze
SIZE =
8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, client_id) ⇒ CheckDigit

Returns a new instance of CheckDigit.



9
10
11
12
# File 'lib/czech_post/code_generator/check_digit.rb', line 9

def initialize(order, client_id)
  @order = order
  @client_id = client_id
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



7
8
9
# File 'lib/czech_post/code_generator/check_digit.rb', line 7

def client_id
  @client_id
end

#orderObject (readonly)

Returns the value of attribute order.



7
8
9
# File 'lib/czech_post/code_generator/check_digit.rb', line 7

def order
  @order
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
# File 'lib/czech_post/code_generator/check_digit.rb', line 14

def run
  if modulo > 1
    11 - modulo
  elsif modulo == 0
    5
  elsif modulo == 1
    0
  end
end

#valid?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/czech_post/code_generator/check_digit.rb', line 24

def valid?
  size == SIZE
end