Class: Pickup::CircleIterator
- Inherits:
-
Object
- Object
- Pickup::CircleIterator
- Defined in:
- lib/pickup.rb
Instance Attribute Summary collapse
-
#func ⇒ Object
readonly
Returns the value of attribute func.
-
#key_func ⇒ Object
readonly
Returns the value of attribute key_func.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
-
#weight_func ⇒ Object
readonly
Returns the value of attribute weight_func.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(obj, func, max, opts = {}) ⇒ CircleIterator
constructor
A new instance of CircleIterator.
Constructor Details
#initialize(obj, func, max, opts = {}) ⇒ CircleIterator
Returns a new instance of CircleIterator.
35 36 37 38 39 40 41 |
# File 'lib/pickup.rb', line 35 def initialize(obj, func, max, opts={}) @obj = obj.dup @func = func @max = max @key_func = opts[:key_func] || key_func @weight_func = opts[:weight_func] || weight_func end |
Instance Attribute Details
#func ⇒ Object (readonly)
Returns the value of attribute func.
33 34 35 |
# File 'lib/pickup.rb', line 33 def func @func end |
#key_func ⇒ Object (readonly)
Returns the value of attribute key_func.
33 34 35 |
# File 'lib/pickup.rb', line 33 def key_func @key_func end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
33 34 35 |
# File 'lib/pickup.rb', line 33 def max @max end |
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
33 34 35 |
# File 'lib/pickup.rb', line 33 def obj @obj end |
#weight_func ⇒ Object (readonly)
Returns the value of attribute weight_func.
33 34 35 |
# File 'lib/pickup.rb', line 33 def weight_func @weight_func end |
Instance Method Details
#each ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/pickup.rb', line 59 def each until obj.empty? start = 0 obj.each do |item| key = key_func.call(item) weight = weight_func.call(item) val = func.call(weight) start += val if yield([key, start, max]) obj.delete key @max -= val end end end end |