Class: Ekylibre::FirstRun::Counter
- Inherits:
-
Object
- Object
- Ekylibre::FirstRun::Counter
- Defined in:
- lib/ekylibre/first_run/counter.rb
Defined Under Namespace
Classes: CountExceeded
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Instance Method Summary collapse
- #check_point(increment = 1) ⇒ Object
-
#initialize(maximum = 0, &block) ⇒ Counter
constructor
A new instance of Counter.
Constructor Details
#initialize(maximum = 0, &block) ⇒ Counter
Returns a new instance of Counter.
9 10 11 12 13 |
# File 'lib/ekylibre/first_run/counter.rb', line 9 def initialize(maximum = 0, &block) @count = 0 @maximum = maximum @block = block if block_given? end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count
4 5 6 |
# File 'lib/ekylibre/first_run/counter.rb', line 4 def count @count end |
Instance Method Details
#check_point(increment = 1) ⇒ Object
15 16 17 18 19 |
# File 'lib/ekylibre/first_run/counter.rb', line 15 def check_point(increment = 1) @count += increment @block.call(@count, increment) if @block raise CountExceeded if @maximum > 0 && @count >= @maximum end |