Module: Genny::Array
- Defined in:
- lib/genny/array.rb
Class Method Summary collapse
-
.genny(opts = {}) ⇒ Array
Generates an array of items of the types specified.
Class Method Details
.genny(opts = {}) ⇒ Array
Generates an array of items of the types specified.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/genny/array.rb', line 22 def self.genny(opts = {}) opts = Genny.symbolize(opts) opts[:items] = opts[:items].is_a?(::Array) ? opts[:items] : [opts[:items]].compact raise ArgumentError, "classes must be an array" unless opts[:items].respond_to?(:select) items = opts[:items].select { |item| item.respond_to?(:genny) } if items.empty? raise "No items given, cannot populate the array." unless opts[:minItems].to_i == 0 return [] end min_count = opts[:minItems] || 1 max_count = opts[:maxItems] || [min_count, 5].max raise "maxItems is lower than minItems" if max_count < min_count count = Random.rand(max_count - min_count + 1) + min_count return count.times.map { items.sample.genny } end |