Sha256: 417bd1802415693c425016c371f609b13cca2ef474a522e418679ab6aeba2563

Contents?: true

Size: 512 Bytes

Versions: 11

Compression:

Stored size: 512 Bytes

Contents

class String

  # Adds a newline character unless
  # this string is empty or already ends with a newline
  # See https://unix.stackexchange.com/a/18789
  def ensure_newline
    empty? || ends_with?("\n") ? self : self + "\n"
  end

  def friendlish
    I18n.transliterate(self).
      downcase.
      gsub(/[^0-9a-z ]/, '').
      squish.
      gsub(' ', '-')
  end

  def markdown_paragraphs
    split(/\n\s*\n/)
  end

  def normalize_whitespaces
    gsub(/([^[:ascii:]])/) { $1.blank? ? ' ' : $1 }
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mumuki-laboratory-5.6.3 lib/mumuki/laboratory/extensions/string.rb
mumuki-laboratory-5.6.2 lib/mumuki/laboratory/extensions/string.rb
mumuki-laboratory-5.6.1 lib/mumuki/laboratory/extensions/string.rb
mumuki-laboratory-5.6.0 lib/mumuki/laboratory/extensions/string.rb
mumuki-laboratory-5.5.0 lib/mumuki/laboratory/extensions/string.rb
mumuki-laboratory-5.4.0 lib/mumuki/laboratory/extensions/string.rb
mumuki-laboratory-5.3.0 lib/mumuki/laboratory/extensions/string.rb
mumuki-laboratory-5.2.1 lib/mumuki/laboratory/extensions/string.rb
mumuki-laboratory-5.2.0 lib/mumuki/laboratory/extensions/string.rb
mumuki-laboratory-5.1.1 lib/mumuki/laboratory/extensions/string.rb
mumuki-laboratory-5.1.0 lib/mumuki/laboratory/extensions/string.rb