Sha256: 15c0fb2d9a40e51472f9546ec06c1306e18a5b2b29373ab9e7141e06547dd6d6
Contents?: true
Size: 1.07 KB
Versions: 10
Compression:
Stored size: 1.07 KB
Contents
module UniverseCompiler module Universe module Multiverse DEFAULT_UNIVERSE_NAME = 'Unnamed Universe'.freeze def universes @universes ||= {} end def register(universe) raise UniverseCompiler::Error, "Universe '#{universe.name}' already exists in this continuum !" if universes.keys.include? universe.name universes[universe.name] = universe end def get_unique_name(seed = DEFAULT_UNIVERSE_NAME) max_index = 1 universes.keys.each do |universe_name| universe_name.match /^#{seed}(?:(?: - #)(?<index>\d+))?$/ do |md| index = md['index'] || '1' index = index.to_i max_index = index > max_index ? index : max_index end end if max_index == 1 seed else UniverseCompiler.logger.debug "Universe #{seed} reached its #{max_index} iteration." format_name(seed, max_index) end end private def format_name(name, index) '%s - #%d' % [name, index] end end end end
Version data entries
10 entries across 10 versions & 1 rubygems