Created
April 5, 2014 15:48
-
-
Save jpibarra1130/9993586 to your computer and use it in GitHub Desktop.
A simple ruby snippet to retrieve the id for a vimeo url.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple ruby snippet to get the id for a vimeo url. This was based on this gist: https://gist.github.com/wwdboer/4943672 | |
# This should be able to handle the following formats: | |
# http://vimeo.com/12345 | |
# http://player.vimeo.com/video/12345 | |
# http://player.vimeo.com/video/12345?test=value1 | |
# http://player.vimeo.com/video/12345/?test=value1 | |
# http://vimeo.com/channels/testchannel/12345 | |
# http://vimeo.com/groups/testgroup/videos/1234 | |
def vimeo_id(url) | |
match = url.match(/https?:\/\/(?:[\w]+\.)*vimeo\.com(?:[\/\w]*\/?)?\/(?<id>[0-9]+)[^\s]*/) | |
match[:id] if match.present? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment