Sha256: 89daf6775edd6a5140a98fc36b5f2204587bf8082e8eaa268fd3de1c01ea2855

Contents?: true

Size: 472 Bytes

Versions: 2

Compression:

Stored size: 472 Bytes

Contents

module Egn
  class Parser
    attr_reader :date, :sex

    # Parses the given EGN and returns all information that can be
    # extracted from it: date, sex and region
    def initialize(egn)
      raise ArgumentError, 'Invalid EGN' unless Validator.validate(egn)

      # Extract the correct date
      year, month, day = egn.scan(/.{1,2}/).map(&:to_i)
      year, month = Util.determine_date(year, month)

      @date = Date.new(year.to_i, month, day)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
egn-1.3.4 lib/egn/parser.rb
egn-1.3.3 lib/egn/parser.rb