Module: Pione::Util::Indentation
- Defined in:
- lib/pione/util/indentation.rb
Class Method Summary collapse
-
.cut(text) ⇒ String
Cut indentations of the text.
-
.indent(text, size) ⇒ String
Add Indentation to the text.
Class Method Details
.cut(text) ⇒ String
Cut indentations of the text. This function cuts indentation of all lines with the depth of first line's indentation.
12 13 14 15 16 |
# 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) ⇒ String
Add Indentation to the text.
26 27 28 29 30 |
# 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 |