Class: Sourcify::Proc::Scanner::Counter
- Inherits:
-
Object
- Object
- Sourcify::Proc::Scanner::Counter
show all
- Defined in:
- lib/sourcify/proc/scanner/counter.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Counter.
8
9
10
|
# File 'lib/sourcify/proc/scanner/counter.rb', line 8
def initialize
@counts = [0,0]
end
|
Instance Attribute Details
#counts ⇒ Object
Returns the value of attribute counts.
6
7
8
|
# File 'lib/sourcify/proc/scanner/counter.rb', line 6
def counts
@counts
end
|
Instance Method Details
#balanced? ⇒ Boolean
20
21
22
|
# File 'lib/sourcify/proc/scanner/counter.rb', line 20
def balanced?
@counts.any?(&:zero?)
end
|
#decrement ⇒ Object
24
25
26
|
# File 'lib/sourcify/proc/scanner/counter.rb', line 24
def decrement
(0..1).each{|i| @counts[i] -= 1 unless @counts[i].zero? }
end
|
#increment(val = 1) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/sourcify/proc/scanner/counter.rb', line 28
def increment(val = 1)
if val.is_a?(Range)
@counts[0] += val.first
@counts[1] += val.last
else
(0..1).each{|i| @counts[i] += 1 }
end
end
|
#just_started? ⇒ Boolean
16
17
18
|
# File 'lib/sourcify/proc/scanner/counter.rb', line 16
def just_started?
@counts.any?{|count| count == 1 }
end
|
#started? ⇒ Boolean
12
13
14
|
# File 'lib/sourcify/proc/scanner/counter.rb', line 12
def started?
@counts.any?(&:nonzero?)
end
|