Sha256: ef483dcd36be551ad692cc7229818c8243e395c18c55fee211072b37d49db663
Contents?: true
Size: 922 Bytes
Versions: 1
Compression:
Stored size: 922 Bytes
Contents
# frozen_string_literal: true module NameQ module Support class Pool # Take a name from the available pool of names, # suffixed if necessary. # @param name [String] the name to find a variant of within the pool # @return [String] the resolved name from the pool def take(name) return list.add(name) unless list.include?(name) resolve(entry_factory.new(name)).tap { |n| list.add(n) } end protected attr_reader :list def initialize(list) @list = list end def entry_factory Support::StringEntry end private def resolve(entry) suffixes.each do |suffix| resolution = entry.resolve(suffix) return resolution unless list.include?(resolution) end end def suffixes (1..Float::INFINITY).lazy.map { |i| Suffix.new(i) } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nameq-0.0.3 | lib/nameq/support/pool.rb |