Sha256: 5b06a4c481f75858a7c41832d7bb6e44e844bfd0b2384601294ba6384231d9ce

Contents?: true

Size: 752 Bytes

Versions: 10

Compression:

Stored size: 752 Bytes

Contents

# frozen_string_literal: true
module Slack
  module Messages
    module Formatting
      class << self
        #
        # Unescape a message.
        # @see https://api.slack.com/docs/formatting
        #
        def unescape(message)
          CGI.unescapeHTML(message.gsub(/[“”]/, '"')
            .gsub(/[‘’]/, "'")
            .gsub(/<(?<sign>[?@#!]?)(?<dt>.*?)>/) do
              sign = Regexp.last_match[:sign]
              dt = Regexp.last_match[:dt]
              rhs = dt.split('|', 2).last
              case sign
              when '@', '!'
                "@#{rhs}"
              when '#'
                "##{rhs}"
              else
                rhs
              end
            end)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
slack-ruby-client-2.1.0 lib/slack/messages/formatting.rb
slack-ruby-client-2.0.0 lib/slack/messages/formatting.rb
slack-ruby-client-1.1.0 lib/slack/messages/formatting.rb
slack-ruby-client-1.0.0 lib/slack/messages/formatting.rb
slack-ruby-client-0.17.0 lib/slack/messages/formatting.rb
slack-ruby-client-0.16.0 lib/slack/messages/formatting.rb
slack-ruby-client-0.15.1 lib/slack/messages/formatting.rb
slack-ruby-client-0.15.0 lib/slack/messages/formatting.rb
slack-ruby-client-0.14.6 lib/slack/messages/formatting.rb
slack-ruby-client-0.14.5 lib/slack/messages/formatting.rb