Class: Cdigits::Luhn::Placeholder
- Inherits:
-
Object
- Object
- Cdigits::Luhn::Placeholder
- Defined in:
- lib/cdigits/luhn/placeholder.rb
Constant Summary collapse
- NON_ZERO_SYMBOL =
'+'
- NUMERIC_SYMBOL =
'#'
- CHECK_DIGIT_SYMBOL =
Note:
any good idia?
'?'
Instance Method Summary collapse
-
#fill(placeholder) ⇒ String
Generate code.
-
#initialize(characters) ⇒ Placeholder
constructor
A new instance of Placeholder.
-
#valid?(placeholder) ⇒ Boolean
Validate code.
Constructor Details
#initialize(characters) ⇒ Placeholder
Returns a new instance of Placeholder.
14 15 16 |
# File 'lib/cdigits/luhn/placeholder.rb', line 14 def initialize(characters) @characters = characters end |
Instance Method Details
#fill(placeholder) ⇒ String
Generate code
21 22 23 24 25 26 27 28 29 |
# File 'lib/cdigits/luhn/placeholder.rb', line 21 def fill(placeholder) codes = [] store = build_store(placeholder) do |char, digit| codes << (digit.nil? ? char : nil) end store.fill_check_digit generate_code(codes, store.digits) end |
#valid?(placeholder) ⇒ Boolean
Validate code
34 35 36 37 |
# File 'lib/cdigits/luhn/placeholder.rb', line 34 def valid?(placeholder) store = build_store(placeholder) (store.sum % modulus).zero? end |