lib/jan/validator.rb in jan-0.0.1 vs lib/jan/validator.rb in jan-0.0.2
- old
+ new
@@ -4,11 +4,17 @@
class Jan
module Validator
module_function
def validate(code)
- code = code.to_s
- return false unless [8,13].include?(code.size)
+ validate_size(code.to_s) && validate_check_digit(code.to_s)
+ end
+
+ def validate_size(code)
+ [8,13].include?(code.to_s.size)
+ end
+
+ def validate_check_digit(code)
Parser.check_digit(code) == CheckDigitCalculator.calculate(Parser.body(code))
end
end
end