Class: Base32::Random
- Inherits:
-
Object
- Object
- Base32::Random
- Defined in:
- lib/base32/random.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#padding ⇒ Object
readonly
Returns the value of attribute padding.
Instance Method Summary collapse
- #alphabet ⇒ Object
- #call ⇒ Object
-
#initialize(length = 16, padding = true) ⇒ Random
constructor
A new instance of Random.
Constructor Details
#initialize(length = 16, padding = true) ⇒ Random
Returns a new instance of Random.
10 11 12 13 |
# File 'lib/base32/random.rb', line 10 def initialize(length = 16, padding = true) @length = length @padding = padding end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
8 9 10 |
# File 'lib/base32/random.rb', line 8 def length @length end |
#padding ⇒ Object (readonly)
Returns the value of attribute padding.
8 9 10 |
# File 'lib/base32/random.rb', line 8 def padding @padding end |
Instance Method Details
#alphabet ⇒ Object
24 25 26 |
# File 'lib/base32/random.rb', line 24 def alphabet @alphabet ||= Base32::Alphabet.new Base32::Alphabet::CHARS end |
#call ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/base32/random.rb', line 15 def call random = '' OpenSSL::Random.random_bytes(length).each_byte do |b| random += alphabet.to_s[b % 32] end padding ? random.ljust((length / 8.0).ceil * 8, '=') : random end |