Class: Slack::Notifier::Util::LinkFormatter
- Inherits:
-
Object
- Object
- Slack::Notifier::Util::LinkFormatter
- Defined in:
- lib/slack-notifier/util/link_formatter.rb
Constant Summary collapse
- HTML_PATTERN =
/ <a (?:.*?) href=['"](.+?)['"] (?:.*?)> (.+?) <\/a> /x
- MARKDOWN_PATTERN =
/\[ ([^\[\]]*?) \] \( ((https?:\/\/.*?) | (mailto:.*?)) \) /x
Instance Attribute Summary collapse
-
#formats ⇒ Object
readonly
Returns the value of attribute formats.
Class Method Summary collapse
Instance Method Summary collapse
-
#formatted ⇒ Object
rubocop:disable Style/GuardClause.
-
#initialize(string, formats: [:html, :markdown]) ⇒ LinkFormatter
constructor
A new instance of LinkFormatter.
Constructor Details
#initialize(string, formats: [:html, :markdown]) ⇒ LinkFormatter
Returns a new instance of LinkFormatter.
20 21 22 23 |
# File 'lib/slack-notifier/util/link_formatter.rb', line 20 def initialize string, formats: [:html, :markdown] @formats = formats @orig = string.respond_to?(:scrub) ? string.scrub : string end |
Instance Attribute Details
#formats ⇒ Object (readonly)
Returns the value of attribute formats.
18 19 20 |
# File 'lib/slack-notifier/util/link_formatter.rb', line 18 def formats @formats end |
Class Method Details
.format(string, opts = {}) ⇒ Object
13 14 15 |
# File 'lib/slack-notifier/util/link_formatter.rb', line 13 def format string, opts={} LinkFormatter.new(string, opts).formatted end |
Instance Method Details
#formatted ⇒ Object
rubocop:disable Style/GuardClause
26 27 28 29 30 31 32 33 34 |
# File 'lib/slack-notifier/util/link_formatter.rb', line 26 def formatted sub_markdown_links(sub_html_links(@orig)) rescue => e if RUBY_VERSION < "2.1" && e..include?("invalid byte sequence") raise e, "#{e.}. Consider including the 'string-scrub' gem to strip invalid characters" else raise e end end |