module Pione::Util::Indentation

Public Class Methods

cut(text) click to toggle source

Cut indentations of the text. This function cuts indentation of all lines with the depth of first line’s indentation.

@param text [String]

the text

@return [String]

indentation cutted text
# File lib/pione/util/indentation.rb, line 12
def self.cut(text)
  line = text.lines.to_a.first
  n = line.length - line.lstrip.length
  n > 0 ? text.gsub(/^[ ]{0,#{n}}/m, "") : text
end
indent(text, size) click to toggle source

Add Indentation to the text.

@param text [String]

the text

@param size [Integer]

indentaion size

@return [String]

indented text
# File lib/pione/util/indentation.rb, line 26
def self.indent(text, size)
  text.lines.each_with_object("") do |line, indented|
    indented << " " * size + line
  end
end