Created
March 6, 2012 13:08
-
-
Save mono0x/1986179 to your computer and use it in GitHub Desktop.
Open URI with default web browser
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
require 'uri' | |
class WebBrowser | |
def self.open(uri) | |
uri = URI.parse(uri.to_s) | |
unless %w[ http https ftp file ].include?(uri.scheme) | |
raise ArgumentError | |
end | |
case RUBY_PLATFORM | |
when /mswin(?!ce)|mingw|bccwin/ | |
system %!start /B #{uri}! | |
when /cygwin/ | |
system %!cmd /C start /B #{uri}! | |
when /darwin/ | |
system %!open '#{uri}'! | |
when /linux/ | |
system %!xdg-open '#{uri}'! | |
when /java/ | |
require 'java' | |
import 'java.awt.Desktop' | |
import 'java.net.URI' | |
Desktop.getDesktop.browse java.net.URI.new(uri) | |
else | |
raise NotImplementedError | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment