Class: Slack::Notifier::LinkFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/slack-notifier/link_formatter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ LinkFormatter

Returns a new instance of LinkFormatter.



13
14
15
# File 'lib/slack-notifier/link_formatter.rb', line 13

def initialize string
  @orig = string
end

Class Method Details

.format(string) ⇒ Object



7
8
9
# File 'lib/slack-notifier/link_formatter.rb', line 7

def format string
  LinkFormatter.new(string).formatted
end

Instance Method Details

#formattedObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/slack-notifier/link_formatter.rb', line 17

def formatted
  @orig.gsub( html_pattern ) do |match|
    link = Regexp.last_match[1]
    text = Regexp.last_match[2]
    slack_link link, text
  end.gsub( markdown_pattern ) do |match|
    link = Regexp.last_match[2]
    text = Regexp.last_match[1]
    slack_link link, text
  end
end