Sha256: 1c9511b480c78c927a750efede018158af490be89637a74bcfeb09e5a86c7930

Contents?: true

Size: 489 Bytes

Versions: 3

Compression:

Stored size: 489 Bytes

Contents

module Pione

  module Util
    module Indentation
      # 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
      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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pione-0.4.1 lib/pione/util/indentation.rb
pione-0.4.0 lib/pione/util/indentation.rb
pione-0.3.2 lib/pione/util/indentation.rb