class Termtter::TypableIdGenerator
Public Class Methods
new(ids)
click to toggle source
# File lib/plugins/defaults/stdout.rb, line 42 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 = {} @rtable = {} end
Public Instance Methods
get(id)
click to toggle source
# File lib/plugins/defaults/stdout.rb, line 62 def get(id) @table[id] end
get_id(data)
click to toggle source
# File lib/plugins/defaults/stdout.rb, line 66 def get_id(data) @rtable[data] || self.next(data) end
next(data)
click to toggle source
# File lib/plugins/defaults/stdout.rb, line 53 def next(data) id = @ids.shift @ids.push id @rtable.delete(@table[id]) @table[id] = data @rtable[data] = id id end