Class: Test::Right::DataFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/test/right/data_factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ DataFactory

Returns a new instance of DataFactory.



6
7
8
9
# File 'lib/test/right/data_factory.rb', line 6

def initialize(template)
  @template = template
  @used_ids = Set.new([nil])
end

Instance Method Details

#[](name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/test/right/data_factory.rb', line 11

def [](name)
  base = @template[name] || @template[name.to_s] || name.to_s
  id = nil
  while @used_ids.include? id
    id = rand(100000)
  end
  base += id.to_s
  return base
end