Class: Egn::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/egn/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(egn) ⇒ Parser

Parses the given EGN and returns all information that can be extracted from it: date, sex and region

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
# File 'lib/egn/parser.rb', line 7

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

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



3
4
5
# File 'lib/egn/parser.rb', line 3

def date
  @date
end

#sexObject (readonly)

Returns the value of attribute sex.



3
4
5
# File 'lib/egn/parser.rb', line 3

def sex
  @sex
end