Class: Egn::Parser
- Inherits:
-
Object
- Object
- Egn::Parser
- Defined in:
- lib/egn/parser.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#sex ⇒ Object
readonly
Returns the value of attribute sex.
Instance Method Summary collapse
-
#initialize(egn) ⇒ Parser
constructor
Parses the given EGN and returns all information that can be extracted from it: date, sex and region.
Constructor Details
#initialize(egn) ⇒ Parser
Parses the given EGN and returns all information that can be extracted from it: date, sex and region
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
#date ⇒ Object (readonly)
Returns the value of attribute date.
3 4 5 |
# File 'lib/egn/parser.rb', line 3 def date @date end |
#sex ⇒ Object (readonly)
Returns the value of attribute sex.
3 4 5 |
# File 'lib/egn/parser.rb', line 3 def sex @sex end |