Sha256: 4f776ce6b3d9071603b28d65c8bcdb87cd7201ae346ecd931c91e4776fe8fa64

Contents?: true

Size: 835 Bytes

Versions: 9

Compression:

Stored size: 835 Bytes

Contents

module Sourcify
  module Proc
    module Scanner #:nodoc:all
      class Counter

        attr_reader :counts

        def initialize
          @counts = [0,0]
        end

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

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

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

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

        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

      end

      class DoEndBlockCounter < Counter; end
      class BraceBlockCounter < Counter; end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sourcify-0.5.0 lib/sourcify/proc/scanner/counter.rb
sourcify-0.4.2 lib/sourcify/proc/scanner/counter.rb
sourcify-0.4.1 lib/sourcify/proc/scanner/counter.rb
sourcify-0.4.0 lib/sourcify/proc/scanner/counter.rb
sourcify-0.3.0 lib/sourcify/proc/scanner/counter.rb
sourcify-0.2.3 lib/sourcify/proc/scanner/counter.rb
sourcify-0.2.2.1 lib/sourcify/proc/scanner/counter.rb
sourcify-0.2.1 lib/sourcify/proc/scanner/counter.rb
sourcify-0.2.0 lib/sourcify/proc/scanner/counter.rb