Class: SwedishPIN::Generator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/swedish_pin/generator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Generator for PINs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date) ⇒ Generator

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.

Creates a new generator for a particular date.


15
16
17
# File 'lib/swedish_pin/generator.rb', line 15

def initialize(date)
  @date = date || random_date
end

Instance Attribute Details

#dateObject (readonly)

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.

The date all generated PINs will be based on.


12
13
14
# File 'lib/swedish_pin/generator.rb', line 12

def date
  @date
end

Instance Method Details

#generate(sequence_number) ⇒ 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.

Generate a Personnummer with the given sequence number.


20
21
22
23
24
25
26
27
28
29
# File 'lib/swedish_pin/generator.rb', line 20

def generate(sequence_number)
  sequence_number ||= random_sequence_number
  Personnummer.new(
    year: date.year,
    month: date.month,
    day: date.day,
    sequence_number: sequence_number,
    control_digit: control_digit(sequence_number)
  )
end