class StaticUID::Million

Public Class Methods

capacity() click to toggle source
# File lib/static_uid/million.rb, line 10
def self.capacity
  lookup_table.size
end
fetch_lookup_table() click to toggle source
# File lib/static_uid/million.rb, line 14
def self.fetch_lookup_table
  capacity
end
generate(i) click to toggle source
# File lib/static_uid/million.rb, line 4
def self.generate(i)
  ensure_capacity!(i)

  lookup_table[i]
end

Private Class Methods

build_lookup_table() click to toggle source
# File lib/static_uid/million.rb, line 30
def self.build_lookup_table
  File.open(lookup_table_file).to_a.map(&:strip)
end
ensure_capacity!(i) click to toggle source
# File lib/static_uid/million.rb, line 20
def self.ensure_capacity!(i)
  if i >= capacity
    raise RuntimeError, "Capacity (#{capacity}) exceeded with #{i}"
  end
end
lookup_table() click to toggle source
# File lib/static_uid/million.rb, line 26
def self.lookup_table
  @lookup_table ||= build_lookup_table
end
lookup_table_file() click to toggle source
# File lib/static_uid/million.rb, line 34
def self.lookup_table_file
  File.expand_path File.join('..', 'lookup_tables', 'million'), __FILE__
end