Class: EmbedRb::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/embedrb/embed_url.rb

Overview

input = “hoge www.youtubue.com/watch?a=b donen hoge.fug/d” url = Embed::Url.new(input, => {:target => ‘_blank’}) print(url.process)

Instance Method Summary collapse

Constructor Details

#initialize(input, output, options, embeds) ⇒ Url

Returns a new instance of Url.



8
9
10
11
12
# File 'lib/embedrb/embed_url.rb', line 8

def initialize(input, output, options, embeds)
  @input = input
  @options = options
  @url_regex = EmbedRb.url_regex
end

Instance Method Details

#processObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/embedrb/embed_url.rb', line 14

def process()
  config = EmbedRb.option(@options, :linkOptions)
  @input.gsub(@url_regex) {|match|
    extention = nil
    if match.include?(".")
      extention = match[match.rindex(".")+1, match.length].downcase
    end
    if config[:exclude].include? extention
      match
    else
      "<a href=\"#{EmbedRb.to_url(match)}\" rel=\"#{config[:rel]}\" target=\"#{config[:target]}\">#{match}</a>"
    end
  }
end