Class: NameQ::Support::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/nameq/support/pool.rb

Direct Known Subclasses

Directory, TextPool

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list) ⇒ Pool (protected)

Returns a new instance of Pool.



19
20
21
# File 'lib/nameq/support/pool.rb', line 19

def initialize(list)
  @list = list
end

Instance Attribute Details

#listObject (readonly, protected)

Returns the value of attribute list.



17
18
19
# File 'lib/nameq/support/pool.rb', line 17

def list
  @list
end

Instance Method Details

#entry_factoryObject (protected)



23
24
25
# File 'lib/nameq/support/pool.rb', line 23

def entry_factory
  Support::StringEntry
end

#take(name) ⇒ String

Take a name from the available pool of names, suffixed if necessary.

Parameters:

  • name (String)

    the name to find a variant of within the pool

Returns:

  • (String)

    the resolved name from the pool



10
11
12
13
# File 'lib/nameq/support/pool.rb', line 10

def take(name)
  return list.add(name) unless list.include?(name)
  resolve(entry_factory.new(name)).tap { |n| list.add(n) }
end