Class: ApiBomb::Path::Weighted
- Inherits:
-
Object
- Object
- ApiBomb::Path::Weighted
- Defined in:
- lib/api_bomb/path.rb
Instance Attribute Summary collapse
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#weighted_paths ⇒ Object
readonly
Returns the value of attribute weighted_paths.
Instance Method Summary collapse
-
#initialize(paths) ⇒ Weighted
constructor
A new instance of Weighted.
- #pick ⇒ Object
- #report(base_url) ⇒ Object
Constructor Details
#initialize(paths) ⇒ Weighted
Returns a new instance of Weighted.
72 73 74 75 |
# File 'lib/api_bomb/path.rb', line 72 def initialize(paths) @weighted_paths = Pickup.new(paths) @paths = paths end |
Instance Attribute Details
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
71 72 73 |
# File 'lib/api_bomb/path.rb', line 71 def paths @paths end |
#weighted_paths ⇒ Object (readonly)
Returns the value of attribute weighted_paths.
71 72 73 |
# File 'lib/api_bomb/path.rb', line 71 def weighted_paths @weighted_paths end |
Instance Method Details
#pick ⇒ Object
77 78 79 |
# File 'lib/api_bomb/path.rb', line 77 def pick Single.new(@weighted_paths.pick) end |
#report(base_url) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# 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 |