class String

The nil-safe affable pipeline goes as follow:

i18n > markdownified > sanitized > affable

Where:

* i18n: translates to current locale
* markdownified: interpretes markdown in message and generates HTML
* sanitized: sanitizes results HTML
* affable: changes structure to hide low level details

Other classes may polymorphically implement their own markdownified, sanitized and affable methods with similar semantics to extend this pipeline to non-strings

Public Instance Methods

affable() click to toggle source

Creates a humman representation - but not necessary UI - representation of this string by interpreting its markdown as a one-liner and sanitizing it

# File lib/mumuki/domain/extensions/string.rb, line 49
def affable
  markdownified(one_liner: true).sanitized
end
ensure_newline() click to toggle source

Adds a newline character unless this string is empty or already ends with a newline See unix.stackexchange.com/a/18789

# File lib/mumuki/domain/extensions/string.rb, line 6
def ensure_newline
  empty? || ends_with?("\n") ? self : self + "\n"
end
file_extension() click to toggle source
# File lib/mumuki/domain/extensions/string.rb, line 26
def file_extension
  File.extname(self).delete '.'
end
friendlish() click to toggle source
# File lib/mumuki/domain/extensions/string.rb, line 10
def friendlish
  I18n.transliterate(self).
    downcase.
    gsub(/[^0-9a-z ]/, '').
    squish.
    gsub(' ', '-')
end
markdown_paragraphs() click to toggle source
# File lib/mumuki/domain/extensions/string.rb, line 18
def markdown_paragraphs
  split(/\n\s*\n/)
end
markdownified(**options) click to toggle source

Interprets the markdown on this string, and converts it into HTML

# File lib/mumuki/domain/extensions/string.rb, line 54
def markdownified(**options)
  Mumukit::ContentType::Markdown.to_html self, options
end
normalize_whitespaces() click to toggle source
# File lib/mumuki/domain/extensions/string.rb, line 22
def normalize_whitespaces
  gsub(/([^[:ascii:]])/) { $1.blank? ? ' ' : $1 }
end
randomize_with(randomizer, seed) click to toggle source
# File lib/mumuki/domain/extensions/string.rb, line 63
def randomize_with(randomizer, seed)
  randomizer.randomize!(self, seed)
end
sanitized() click to toggle source

Sanitizes this string, escaping unsafe HTML sequences

# File lib/mumuki/domain/extensions/string.rb, line 59
def sanitized
  Mumukit::ContentType::Sanitizer.sanitize self
end