class ApiBomb::Path::Weighted

Attributes

paths[R]
weighted_paths[R]

Public Class Methods

new(paths) click to toggle source
# File lib/api_bomb/path.rb, line 72
def initialize(paths)
  @weighted_paths = Pickup.new(paths)
  @paths = paths
end

Public Instance Methods

pick() click to toggle source
# File lib/api_bomb/path.rb, line 77
def pick
  Single.new(@weighted_paths.pick)
end
report(base_url) click to toggle source
# File lib/api_bomb/path.rb, line 81
def report(base_url)
  sum = paths.values.sum

  str_array = []
  str_array << "Load generation over random (weighted) urls \n"
  paths.sort_by {|_key, value| value}.to_h.each do |path, weight|
    str_array << "#{Single.new(path).report(base_url)} with probability #{weight/sum} \n"
  end

  return str_array.join(' ')
end