Class: SwedishPIN::Parser Private
- Inherits:
-
Object
- Object
- SwedishPIN::Parser
- Defined in:
- lib/swedish_pin/parser.rb
Overview
Instance Method Summary collapse
-
#initialize(input, now = Time.now) ⇒ Parser
constructor
private
Setup a new parser.
-
#parse ⇒ Object
private
Return
Hash
of parsed values to be used with SwedishPIN::Personnummer#initialize. -
#valid? ⇒ Boolean
private
Check validity without raising.
-
#validate ⇒ Object
private
Raise ParseError if anything in the input isn’t valid.
Constructor Details
#initialize(input, now = Time.now) ⇒ Parser
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Setup a new parser.
24 25 26 27 28 29 30 31 32 |
# File 'lib/swedish_pin/parser.rb', line 24 def initialize(input, now = Time.now) unless input.is_a?(String) raise ArgumentError, "Expected String, got #{input.inspect}" end @input = input @now = now @matches = MATCHER.match(input.strip) end |
Instance Method Details
#parse ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return Hash
of parsed values to be used with SwedishPIN::Personnummer#initialize.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/swedish_pin/parser.rb', line 50 def parse validate { year: full_year, month: month, day: day, sequence_number: sequence_number, control_digit: control_digit } end |
#valid? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check validity without raising.
42 43 44 45 46 47 |
# File 'lib/swedish_pin/parser.rb', line 42 def valid? validate true rescue false end |
#validate ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Raise SwedishPIN::ParseError if anything in the input isn’t valid.
35 36 37 38 39 |
# File 'lib/swedish_pin/parser.rb', line 35 def validate validate_match validate_luhn validate_date end |