Module: Slack::Messages::Formatting

Defined in:
lib/slack/messages/formatting.rb

Class Method Summary collapse

Class Method Details

.unescape(message) ⇒ Object

Unescape a message.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/slack/messages/formatting.rb', line 10

def unescape(message)
  CGI.unescapeHTML(message.gsub(/[“”]/, '"')
    .gsub(/[‘’]/, "'")
    .gsub(/<(?<sign>[?@#!]?)(?<dt>.*?)>/) do |match|
      sign = $~[:sign]
      dt = $~[:dt]
      rhs = dt.split('|', 2).last
      case sign
      when '@', '!'
        "@#{rhs}"
      when '#'
        "##{rhs}"
      else
        rhs
      end
    end)
end