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.



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

def initialize(list)
  @list = list
end

Instance Attribute Details

#listObject (readonly, protected)

Returns the value of attribute list.



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

def list
  @list
end

Instance Method Details

#entry_factoryObject (protected)



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

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



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

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