Class: Sourcify::Common::Parser::RawScanner::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/sourcify/lib/sourcify/common/parser/raw_scanner/counter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCounter

Returns a new instance of Counter.



9
10
11
# File 'lib/sourcify/lib/sourcify/common/parser/raw_scanner/counter.rb', line 9

def initialize
  @counts = [0,0]
end

Instance Attribute Details

#countsObject (readonly)

Returns the value of attribute counts.



7
8
9
# File 'lib/sourcify/lib/sourcify/common/parser/raw_scanner/counter.rb', line 7

def counts
  @counts
end

Instance Method Details

#balanced?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/sourcify/lib/sourcify/common/parser/raw_scanner/counter.rb', line 21

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

#decrementObject



25
26
27
# File 'lib/sourcify/lib/sourcify/common/parser/raw_scanner/counter.rb', line 25

def decrement
  (0..1).each{|i| @counts[i] -= 1 unless @counts[i].zero? }
end

#increment(val = 1) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/sourcify/lib/sourcify/common/parser/raw_scanner/counter.rb', line 29

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)


17
18
19
# File 'lib/sourcify/lib/sourcify/common/parser/raw_scanner/counter.rb', line 17

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

#started?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/sourcify/lib/sourcify/common/parser/raw_scanner/counter.rb', line 13

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