Skip to content

Instantly share code, notes, and snippets.

@pfeiffer
Created February 2, 2012 20:54
Show Gist options
  • Save pfeiffer/1725693 to your computer and use it in GitHub Desktop.
Save pfeiffer/1725693 to your computer and use it in GitHub Desktop.
class WorkoutLink < ActiveRecord::Base
belongs_to :workout
YOUTUBE_REGEXP = /youtu(?:\.be\/|be\.com\/watch\?v=)(\w{11})/
VIMEO_REGEXP = /vimeo\.com\/([\d+]+)/
def youtube_video_id
$1 if url =~ YOUTUBE_REGEXP
end
def youtube?
youtube_video_id.present?
end
def vimeo_video_id
$1 if url =~ VIMEO_REGEXP
end
def vimeo?
vimeo_video_id.present?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment