Class: Autolinker
- Inherits:
-
Object
- Object
- Autolinker
- Defined in:
- lib/auto-linker/regex.rb,
lib/auto-linker/linker.rb,
lib/auto-linker/config/twitter.rb,
lib/auto-linker/config/instagram.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
-
.parse(text, default_config = Config::INSTAGRAM, config = {}) ⇒ Object
Top level method used to replace handles, hashtags, url and emails with clickable links.
Instance Method Summary collapse
-
#initialize(default_config = Config::INSTAGRAM, config = {}) ⇒ Autolinker
constructor
Merges the default_config and config together.
-
#parse(text) ⇒ Object
Replaces handles, hashtags, url and emails with clickable links.
Constructor Details
#initialize(default_config = Config::INSTAGRAM, config = {}) ⇒ Autolinker
Merges the default_config and config together
19 20 21 |
# File 'lib/auto-linker/linker.rb', line 19 def initialize(default_config = Config::INSTAGRAM, config = {}) @config = default_config.merge(config) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
2 3 4 |
# File 'lib/auto-linker/linker.rb', line 2 def config @config end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
3 4 5 |
# File 'lib/auto-linker/linker.rb', line 3 def text @text end |
Class Method Details
.parse(text, default_config = Config::INSTAGRAM, config = {}) ⇒ Object
Top level method used to replace handles, hashtags, url and emails with clickable links.
10 11 12 |
# 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 |
Instance Method Details
#parse(text) ⇒ Object
Replaces handles, hashtags, url and emails with clickable links.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/auto-linker/linker.rb', line 24 def parse(text) return '' unless text @text = text replace_url replace_handle replace_email replace_hashtag @text end |