Class: BMC::TokenGenerator

Inherits:
Object
  • Object
show all
Defined in:
app/libs/bmc/token_generator.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TokenGenerator

Returns a new instance of TokenGenerator.

[View source]

4
5
6
# File 'app/libs/bmc/token_generator.rb', line 4

def initialize(options = {})
  @options = options
end

Class Attribute Details

.default_alphabetObject


33
34
35
# File 'app/libs/bmc/token_generator.rb', line 33

def default_alphabet
  @default_alphabet ||= (0..9).to_a + ("a".."z").to_a + ("A".."Z").to_a
end

.default_sizeObject


27
28
29
# File 'app/libs/bmc/token_generator.rb', line 27

def default_size
  @default_size ||= 64
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.


2
3
4
# File 'app/libs/bmc/token_generator.rb', line 2

def options
  @options
end

Class Method Details

.callObject

[View source]

21
22
23
# File 'app/libs/bmc/token_generator.rb', line 21

def call(*)
  new(*).call
end

Instance Method Details

#alphabetObject

[View source]

12
13
14
# File 'app/libs/bmc/token_generator.rb', line 12

def alphabet
  options[:alphabet] || self.class.default_alphabet
end

#callObject

[View source]

16
17
18
# File 'app/libs/bmc/token_generator.rb', line 16

def call
  (alphabet * size).sample(size).join
end

#sizeObject

[View source]

8
9
10
# File 'app/libs/bmc/token_generator.rb', line 8

def size
  options[:size] || self.class.default_size
end