class PandaPal::ConsoleHelpers::CodeBuilder
Public Class Methods
Source
# File lib/panda_pal/helpers/console_helpers.rb, line 100 def initialize(indent: 0) @code = "" @line_prefix = [" "] * indent end
Public Instance Methods
Source
# File lib/panda_pal/helpers/console_helpers.rb, line 105 def <<(line) if line.is_a?(Array) line.each do |l| self << l end else bits = line.split("\n", -1) push_bit(bits.shift) bits.each do |bit| @code << "\n" push_bit(bit) end end end
Source
# File lib/panda_pal/helpers/console_helpers.rb, line 127 def block(char = nil) indent!(char) yield ensure dedent! end
Source
# File lib/panda_pal/helpers/console_helpers.rb, line 138 def dedent! @line_prefix.pop end
Source
# File lib/panda_pal/helpers/console_helpers.rb, line 122 def ensure_line return if @code.end_with?("\n") @code << "\n" end
Source
# File lib/panda_pal/helpers/console_helpers.rb, line 134 def indent!(char = nil) @line_prefix << (char || " ") end
Protected Instance Methods
Source
# File lib/panda_pal/helpers/console_helpers.rb, line 148 def push_bit(bit) return unless bit.present? @code << @line_prefix.join if @code.end_with?("\n") @code << bit end