class AsciiTree::ParenthesisToggle

Attributes

on[R]

Public Class Methods

new() click to toggle source
# File lib/ascii_tree/parenthesis_toggle.rb, line 3
def initialize
  @on = false
  @count = 0
end

Public Instance Methods

off?() click to toggle source
# File lib/ascii_tree/parenthesis_toggle.rb, line 29
def off?
  !@on
end
on?() click to toggle source
# File lib/ascii_tree/parenthesis_toggle.rb, line 25
def on?
  @on
end
read(char) click to toggle source
# File lib/ascii_tree/parenthesis_toggle.rb, line 8
def read(char)
  if char == "("
    @on = true
  elsif char == ")"
    @on = false
  end

  if char == "("
    @count += 1
  elsif char == ")"
    @count -= 1
    @count = 0 if @count < 0
  end

  @on = @count > 0
end