Class: Aspera::OpenApplication

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/aspera/open_application.rb

Overview

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOpenApplication



38
39
40
# File 'lib/aspera/open_application.rb', line 38

def initialize
  @url_method=self.class.default_gui_mode
end

Instance Attribute Details

#url_methodObject

Returns the value of attribute url_method.



36
37
38
# File 'lib/aspera/open_application.rb', line 36

def url_method
  @url_method
end

Class Method Details

.default_gui_modeObject



15
16
17
18
19
20
# 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

.uri_graphical(uri) ⇒ Object

command must be non blocking



23
24
25
26
27
28
29
30
31
32
33
34
# 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_interfacesObject

User Interfaces



13
# File 'lib/aspera/open_application.rb', line 13

def self.user_interfaces; [ :text, :graphical ]; end

Instance Method Details

#uri(the_url) ⇒ Object

this is non blocking



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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