Module: Linkable
- Defined in:
- lib/linkable.rb,
lib/linkable/version.rb,
lib/linkable/expression.rb
Constant Summary collapse
- LINK_URI =
Proc.new { |uri| "<a href='#{ uri }'>#{ uri }</a>" }.freeze
- VERSION =
"1.0.0"- EXPRESSION =
/(?<=\A|\s)(((\w+\:)??\/\/)?(([\w\-]+\.){1,}[\w\-]+)(\/[^\? ]+)?([^\s]+)?)(?=\z|\s)/
Instance Method Summary collapse
- #link ⇒ Object
- #link! ⇒ Object
- #replace_urls(&blk) ⇒ Object
- #replace_urls!(&blk) ⇒ Object
- #urls ⇒ Object
Instance Method Details
#link ⇒ Object
23 24 25 |
# File 'lib/linkable.rb', line 23 def link self.gsub(Linkable::EXPRESSION, &LINK_URI) end |
#link! ⇒ Object
27 28 29 |
# File 'lib/linkable.rb', line 27 def link! self.gsub!(Linkable::EXPRESSION, &LINK_URI) end |
#replace_urls(&blk) ⇒ Object
13 14 15 16 |
# File 'lib/linkable.rb', line 13 def replace_urls(&blk) return unless block_given? self.gsub(Linkable::EXPRESSION) { |uri| blk.call URI::parse uri } end |
#replace_urls!(&blk) ⇒ Object
18 19 20 21 |
# File 'lib/linkable.rb', line 18 def replace_urls!(&blk) return unless block_given? self.gsub!(Linkable::EXPRESSION) { |uri| blk.call URI::parse uri } end |
#urls ⇒ Object
9 10 11 |
# File 'lib/linkable.rb', line 9 def urls self.scan(Linkable::EXPRESSION).map(&:first).map { |uri| URI::parse uri } end |