Sha256: f51bb9a8d833e90549ad0e0ace932cc1384c6c15ce76eee403301177b822e46c

Contents?: true

Size: 727 Bytes

Versions: 19

Compression:

Stored size: 727 Bytes

Contents

require 'securerandom'

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)
        if universes[seed]
          format_name seed, SecureRandom.uuid
        else
          seed
        end
      end

      private

      def format_name(name, uuid)
        '%s - #%s' % [name, uuid]
      end

    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
universe_compiler-0.5.6 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.5.5 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.5.4 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.5.3 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.5.2 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.5.1 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.4.3 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.4.2 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.4.1 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.4.0 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.3.12 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.3.11 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.3.10 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.3.9 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.3.8 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.3.7 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.3.6 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.3.5 lib/universe_compiler/universe/multiverse.rb
universe_compiler-0.3.4 lib/universe_compiler/universe/multiverse.rb