Class: Egn::Generator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Generator

Returns a new instance of Generator.



11
12
13
14
15
# File 'lib/egn/generator.rb', line 11

def initialize(options = {})
  validate!(options)
  set_defaults!(options)
  process!
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/egn/generator.rb', line 4

def options
  @options
end

Class Method Details

.generate(options = {}) ⇒ Object

Convenience method



7
8
9
# File 'lib/egn/generator.rb', line 7

def self.generate(options = {})
  Generator.new(options).generate
end

Instance Method Details

#generateObject

The generated EGN will be completely random if no options are given. options is a hash that may have the following keys: :year, :month, :day, :gender



19
20
21
22
23
24
25
26
# File 'lib/egn/generator.rb', line 19

def generate
  egn = format(options[:year]) +
        format(options[:month]) +
        format(options[:day]) +
        format(options[:region], 3)

  egn + Util.egn_checksum(egn).to_s
end