class Aspera::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

default_gui_mode() click to toggle source
# File lib/aspera/open_application.rb, line 15
def self.default_gui_mode
  return :graphical if [Aspera::Environment::OS_WINDOWS,Aspera::Environment::OS_X].include?(Aspera::Environment.os)
  # unix family
  return :graphical if ENV.has_key?("DISPLAY") and !ENV["DISPLAY"].empty?
  return :text
end
new() click to toggle source
# File lib/aspera/open_application.rb, line 38
def initialize
  @url_method=self.class.default_gui_mode
end
uri_graphical(uri) click to toggle source

command must be non blocking

# File lib/aspera/open_application.rb, line 23
def self.uri_graphical(uri)
  case Aspera::Environment.os
  when Aspera::Environment::OS_X
    return system('open',uri.to_s)
  when Aspera::Environment::OS_WINDOWS
    return system('start explorer "'+uri.to_s+'"')
  when Aspera::Environment::OS_LINUX
    return system("xdg-open '#{uri.to_s}'")
  else
    raise "no graphical open method for #{Aspera::Environment.os}"
  end
end
user_interfaces() click to toggle source

User Interfaces

# File lib/aspera/open_application.rb, line 13
def self.user_interfaces; [ :text, :graphical ]; end

Public Instance Methods

uri(the_url) click to toggle source

this is non blocking

# File lib/aspera/open_application.rb, line 43
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