Class: Termtter::TypableIdGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/plugins/defaults/stdout.rb

Instance Method Summary collapse

Constructor Details

#initialize(ids) ⇒ TypableIdGenerator

Returns a new instance of TypableIdGenerator.



22
23
24
25
26
27
28
29
30
# File 'lib/plugins/defaults/stdout.rb', line 22

def initialize(ids)
  if not ids.kind_of?(Array)
    raise ArgumentError, 'ids should be an Array'
  elsif ids.empty?
    raise ArgumentError, 'ids should not be empty'
  end
  @ids = ids
  @table = {}
end

Instance Method Details

#get(id) ⇒ Object



39
40
41
# File 'lib/plugins/defaults/stdout.rb', line 39

def get(id)
  @table[id]
end

#next(data) ⇒ Object



32
33
34
35
36
37
# File 'lib/plugins/defaults/stdout.rb', line 32

def next(data)
  id = @ids.shift
  @ids.push id
  @table[id] = data
  id
end