class Laplus::UI::Indention

Constants

INDENTION_REGEX

Attributes

lines[R]
padding[R]

Public Class Methods

new(lines, padding = ' ') click to toggle source
# File lib/laplus/ui.rb, line 14
def initialize(lines, padding = '  ')
  @lines = lines.clone(freeze: false)
  @padding = padding.freeze
end
split(text) click to toggle source
# File lib/laplus/ui.rb, line 7
def split(text)
  new(text.split("\n"))
end

Public Instance Methods

indent(depth) click to toggle source
# File lib/laplus/ui.rb, line 28
def indent(depth)
  indention = padding * depth
  lines.map { |line| "#{indention}#{line}" }.join("\n")
end
offset() click to toggle source
# File lib/laplus/ui.rb, line 19
def offset
  if (match = lines.first&.match(INDENTION_REGEX))
    indention = match.captures.first
    lines.map! { |line| line.delete_prefix(indention) }
  end

  self
end