Class: TokenChain::Generator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(anchor_code, last_code = nil) ⇒ Generator

Returns a new instance of Generator.



7
8
9
10
11
# File 'lib/token_chain/generator.rb', line 7

def initialize anchor_code, last_code=nil
  @anchor_code = anchor_code
  @last_code   = last_code
  @codes       = []
end

Instance Attribute Details

#anchor_codeObject (readonly)

Returns the value of attribute anchor_code.



5
6
7
# File 'lib/token_chain/generator.rb', line 5

def anchor_code
  @anchor_code
end

#codesObject (readonly)

Returns the value of attribute codes.



5
6
7
# File 'lib/token_chain/generator.rb', line 5

def codes
  @codes
end

Instance Method Details

#generate(quantity = 1) ⇒ Object



13
14
15
16
# File 'lib/token_chain/generator.rb', line 13

def generate quantity=1
  codes = make_new_codes quantity
  quantity > 1 ? codes : codes.last
end

#shaObject



18
19
20
# File 'lib/token_chain/generator.rb', line 18

def sha
  @sha ||= Digest::SHA2.new
end