class Autolinker
Attributes
config[R]
text[R]
Public Class Methods
new(default_config = Config::INSTAGRAM, config = {})
click to toggle source
Merges the default_config and config together
# File lib/auto-linker/linker.rb, line 19 def initialize(default_config = Config::INSTAGRAM, config = {}) @config = default_config.merge(config) end
parse(text, default_config = Config::INSTAGRAM, config = {})
click to toggle source
Top level method used to replace handles, hashtags, url and emails with clickable links.
# File lib/auto-linker/linker.rb, line 10 def self.parse(text, default_config = Config::INSTAGRAM, config = {}) Autolinker.new(default_config, config).parse(text) end
Public Instance Methods
parse(text)
click to toggle source
Replaces handles, hashtags, url and emails with clickable links.
# File lib/auto-linker/linker.rb, line 24 def parse(text) return '' unless text @text = text @text = Rinku.auto_link(@text, mode=:all, "class=\"#{@config[:url_class]}\" target=\"#{@config[:target]}\"") replace_handle replace_hashtag @text end
Private Instance Methods
replace_handle()
click to toggle source
Replaces handles with clickable links
# File lib/auto-linker/linker.rb, line 36 def replace_handle @text.gsub!(Regex::HANDLE, "<a href=\"#{@config[:handle_url_base]}\\1\" class=\"#{@config[:handle_class]}\" target=\"#{@config[:target]}\">@\\1</a>") end
replace_hashtag()
click to toggle source
Replaces hashtags with clickable links
# File lib/auto-linker/linker.rb, line 41 def replace_hashtag @text.gsub!(Regex::HASHTAG, "<a href=\"#{@config[:hashtag_url_base]}\\1\" class=\"#{@config[:hashtag_class]}\" target=\"#{@config[:target]}\">#\\1</a>") end