class Asperalm::OpenApplication
Allows a user to open a Url if method is “text”, then URL is displayed on terminal if method is “graphical”, then the URL will be opened with the default browser.
Attributes
url_method[RW]
Public Class Methods
current_os_type()
click to toggle source
# File lib/asperalm/open_application.rb, line 26 def self.current_os_type case RbConfig::CONFIG['host_os'] when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ return :windows when /darwin|mac os/ return :mac else # unix family return :unix end end
default_gui_mode()
click to toggle source
# File lib/asperalm/open_application.rb, line 14 def self.default_gui_mode case current_os_type when :windows,:mac return :graphical else # unix family if ENV.has_key?("DISPLAY") and !ENV["DISPLAY"].empty? return :graphical end return :text end end
new()
click to toggle source
# File lib/asperalm/open_application.rb, line 51 def initialize @url_method=self.class.default_gui_mode end
uri_graphical(uri)
click to toggle source
command must be non blocking
# File lib/asperalm/open_application.rb, line 38 def self.uri_graphical(uri) case current_os_type when :mac return system('open',uri.to_s) when :windows return system('start explorer "'+uri.to_s+'"') else # unix family return system("xdg-open '#{uri.to_s}'") end end
user_interfaces()
click to toggle source
User Interfaces
# File lib/asperalm/open_application.rb, line 12 def self.user_interfaces; [ :text, :graphical ]; end
Public Instance Methods
uri(the_url)
click to toggle source
this is non blocking
# File lib/asperalm/open_application.rb, line 56 def uri(the_url) case @url_method when :graphical self.class.uri_graphical(the_url) when :text case the_url.to_s when /^http/ puts "USER ACTION: please enter this url in a browser:\n"+the_url.to_s.red()+"\n" else puts "USER ACTION: open this:\n"+the_url.to_s.red()+"\n" end else raise StandardError,"unsupported url open method: #{@url_method}" end end