class Embedda::Filters::Vimeo

Public Class Methods

new(protocol, width, height, vimeo_params) click to toggle source
# File lib/embedda/filters/vimeo.rb, line 7
def initialize(protocol, width, height, vimeo_params)
  @protocol = protocol
  @width    = width
  @height   = height
  @vimeo_params= vimeo_params
end

Public Instance Methods

process(string) click to toggle source
# File lib/embedda/filters/vimeo.rb, line 14
def process(string)
  string.gsub!(/(<a[^>]*?vimeo\.com\/(\d+).*?<\/a>)/i) { |m| player($2) }
  string.gsub!(/([http|https]+:\/\/(?:www\.)?vimeo\.com\/(\d+)\w*)/i) { |m| player($2) }
  return string
end

Private Instance Methods

height_attribute() click to toggle source
# File lib/embedda/filters/vimeo.rb, line 34
def height_attribute
  %Q{ height="#{@height}"} if @height
end
player(token) click to toggle source
# File lib/embedda/filters/vimeo.rb, line 22
def player(token)
  %Q{<iframe src="#{player_url(token)}" width="#{@width}"#{height_attribute} frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>}
end
player_url(token) click to toggle source
# File lib/embedda/filters/vimeo.rb, line 26
def player_url(token)
  url = URI.parse("http://player.vimeo.com/")
  url.scheme = @protocol
  url.path   = "/video/#{token}"
  url.query  = Rack::Utils.build_query @vimeo_params if @vimeo_params
  url.to_s
end