daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Mar 21st, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Format
  2.   ZERO_WIDTH = "​"
  3.  
  4.   def self.i(str)
  5.     "_#{str}_"
  6.   end
  7.  
  8.   def self.b(str)
  9.     "**#{str}**"
  10.   end
  11.  
  12.   def self.bi(str)
  13.     "***#{str}***"
  14.   end
  15.  
  16.   def self.u(str)
  17.     "__#{str}__"
  18.   end
  19.  
  20.   def self.ui(str)
  21.     "__*#{str}*__"
  22.   end
  23.  
  24.   def self.ub(str)
  25.     "__**#{str}**__"
  26.   end
  27.  
  28.   def self.ubi(str)
  29.     "__***#{str}***__"
  30.   end
  31.  
  32.   def self.strike(str)
  33.     "~~#{str}~~"
  34.   end
  35.  
  36.   def self.inline(str)
  37.     "`#{str.gsub("`", "'")}`"
  38.   end
  39.  
  40.   def self.code(str, language: nil)
  41.     str = str.gsub("`") { ZERO_WIDTH * 2 + "`" }
  42.     "```#{language}\n#{str}\n```"
  43.   end
  44.  
  45.   def self.margin(str, margin: 2)
  46.     "\n" + str.lines.map { |l| " " * margin + l }.join + "\n" * 2
  47.   end
  48.  
  49.   def self.escape(str)
  50.     str = str.gsub('\\') { "\\\\" }.gsub("_") { '\\_' }
  51.     str = str.gsub("*") { "\\*" }.gsub("`") { ZERO_WIDTH * 2 + "`" }
  52.     str.gsub("~") { "\\~" }
  53.   end
  54.  
  55.   def self.number(n)
  56.     n = n.to_i if n.to_i == n
  57.  
  58.     ActiveSupport::NumberHelper.number_to_delimited(n)
  59.   end
  60. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top