lib/egn/validator.rb in egn-0.4.0 vs lib/egn/validator.rb in egn-1.0.0
- old
+ new
@@ -1,9 +1,19 @@
module Egn
class Validator
+ attr_reader :egn
- # Checks if a given EGN is valid
+ # Convinience method
def self.validate(egn)
+ Validator.new(egn).validate
+ end
+
+ def initialize(egn)
+ @egn = egn
+ end
+
+ # Checks if a given EGN is valid
+ def validate
return false unless egn.length == 10
# Extract the correct year and month
year, month, day = egn.scan(/.{1,2}/).map(&:to_i)
year, month = Util.determine_date(year, month)