Sha256: f2a9ac37887c337af20d5758d17f26d3ed1d163ca956b3e4d5653bee7e60e3a9

Contents?: true

Size: 611 Bytes

Versions: 25

Compression:

Stored size: 611 Bytes

Contents

module JSONAPIonify
  module IndentedString
    extend self

    refine String do
      def deindent
        shortest_line_length = lines.each_with_object([]) do |line, ary|
          next if line.empty?
          ary << line.match(/^\s*/)[0].length if line.rstrip.present?
        end.sort.first

        lines.map do |string|
          if string.length && !string.match(/^\s*$/)
            string.rstrip[shortest_line_length..-1]
          else
            string
          end
        end.join("\n")
      end
    end

    using self

    def deindent_string(string)
      string.deindent
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
jsonapionify-0.12.10 lib/jsonapionify/indented_string.rb
jsonapionify-0.12.9 lib/jsonapionify/indented_string.rb
jsonapionify-0.12.8 lib/jsonapionify/indented_string.rb
jsonapionify-0.12.7 lib/jsonapionify/indented_string.rb
jsonapionify-0.12.5 lib/jsonapionify/indented_string.rb
jsonapionify-0.12.4 lib/jsonapionify/indented_string.rb
jsonapionify-0.12.3 lib/jsonapionify/indented_string.rb
jsonapionify-0.12.2 lib/jsonapionify/indented_string.rb
jsonapionify-0.12.1 lib/jsonapionify/indented_string.rb
jsonapionify-0.12.0 lib/jsonapionify/indented_string.rb
jsonapionify-0.11.11 lib/jsonapionify/indented_string.rb
jsonapionify-0.11.10 lib/jsonapionify/indented_string.rb
jsonapionify-0.11.9 lib/jsonapionify/indented_string.rb
jsonapionify-0.11.8 lib/jsonapionify/indented_string.rb
jsonapionify-0.11.7 lib/jsonapionify/indented_string.rb
jsonapionify-0.11.6 lib/jsonapionify/indented_string.rb
jsonapionify-0.11.5 lib/jsonapionify/indented_string.rb
jsonapionify-0.11.0 lib/jsonapionify/indented_string.rb
jsonapionify-0.10.2 lib/jsonapionify/indented_string.rb
jsonapionify-0.10.1 lib/jsonapionify/indented_string.rb