Class: Launchy::Spawnable::Browser
- Inherits:
-
Application
- Object
- Application
- Launchy::Spawnable::Browser
- Defined in:
- lib/launchy/spawnable/browser.rb
Constant Summary collapse
- APP_LIST =
{ :windows => %w[ firefox iexplore ], :darwin => %w[ open ], :nix => %w[ firefox ], :unknown => [], }
Constants inherited from Application
Application::KNOWN_OS_FAMILIES
Class Method Summary collapse
-
.handle?(*args) ⇒ Boolean
return true if this class can handle the given parameter(s).
- .run(*args) ⇒ Object
Instance Method Summary collapse
-
#app_list ⇒ Object
returns the list of command line application names for the current os.
-
#browser ⇒ Object
return the full command line path to the browser or nil.
-
#initialize ⇒ Browser
constructor
A new instance of Browser.
-
#visit(url) ⇒ Object
launch the browser at the appointed url.
Methods inherited from Application
application_classes, find_application_class_for, #find_executable, inherited, #my_os, #my_os_family, #run
Constructor Details
#initialize ⇒ Browser
Returns a new instance of Browser.
29 30 31 |
# File 'lib/launchy/spawnable/browser.rb', line 29 def initialize raise "Unable to find browser to launch for os family '#{my_os_family}'." unless browser end |
Class Method Details
.handle?(*args) ⇒ Boolean
return true if this class can handle the given parameter(s)
19 20 21 22 23 24 25 26 |
# File 'lib/launchy/spawnable/browser.rb', line 19 def handle?(*args) begin uri = URI.parse(args[0]) return [URI::HTTP, URI::HTTPS, URI::FTP].include?(uri.class) rescue Exception return false end end |
Instance Method Details
#app_list ⇒ Object
returns the list of command line application names for the current os
34 35 36 |
# File 'lib/launchy/spawnable/browser.rb', line 34 def app_list APP_LIST[my_os_family] end |
#browser ⇒ Object
return the full command line path to the browser or nil
39 40 41 |
# File 'lib/launchy/spawnable/browser.rb', line 39 def browser @browser ||= app_list.collect { |bin| find_executable(bin) }.reject { |x| x.nil? }.first end |
#visit(url) ⇒ Object
launch the browser at the appointed url
44 45 46 |
# File 'lib/launchy/spawnable/browser.rb', line 44 def visit(url) run(browser,url) end |