Class: Sourcify::Proc::Scanner::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/sourcify/proc/scanner/counter.rb

Direct Known Subclasses

BraceBlockCounter, DoEndBlockCounter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCounter

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

#countsObject (readonly)

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

Returns:

  • (Boolean)


20
21
22
# File 'lib/sourcify/proc/scanner/counter.rb', line 20

def balanced?
  @counts.any?(&:zero?)
end

#decrementObject



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

Returns:

  • (Boolean)


16
17
18
# File 'lib/sourcify/proc/scanner/counter.rb', line 16

def just_started?
  @counts.any?{|count| count == 1 }
end

#started?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/sourcify/proc/scanner/counter.rb', line 12

def started?
  @counts.any?(&:nonzero?)
end