Class: Filter::URI

Inherits:
Filter show all
Defined in:
lib/filters/uri.rb

Constant Summary

Constants inherited from Filter

VERSION

Instance Attribute Summary collapse

Attributes inherited from Filter

#string

Instance Method Summary collapse

Methods inherited from Filter

Profanity, Profanity!, #filter, inherited

Constructor Details

#initialize(string, options = {}) ⇒ URI

Initialize with string and options.



14
15
16
17
# File 'lib/filters/uri.rb', line 14

def initialize string, options = {}
  super
  @new_window = options.fetch :new_window, false
end

Instance Attribute Details

#new_windowObject (readonly)

Weither or not to open in a new window.



9
10
11
# File 'lib/filters/uri.rb', line 9

def new_window
  @new_window
end

Instance Method Details

#filter!Object

Convert URIs to anchor tags.



22
23
24
25
26
27
28
29
30
31
# File 'lib/filters/uri.rb', line 22

def filter!
  string.gsub! ::URI.regexp do |uri|
    if new_window
      %(<a href="#{uri}" target="_blank">#{uri}</a>)
    else
      %(<a href="#{uri}">#{uri}</a>)
    end
  end
  string
end