Class: CzechPost::CodeGenerator::CheckDigit
- Inherits:
-
Object
- Object
- CzechPost::CodeGenerator::CheckDigit
- 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
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
-
#initialize(order, client_id) ⇒ CheckDigit
constructor
A new instance of CheckDigit.
- #run ⇒ Object
- #valid? ⇒ Boolean
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_id ⇒ Object (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 |
#order ⇒ Object (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
#run ⇒ Object
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
24 25 26 |
# File 'lib/czech_post/code_generator/check_digit.rb', line 24 def valid? size == SIZE end |