Class: Launchy::Spawnable::Browser

Inherits:
Application show all
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

Instance Method Summary collapse

Methods inherited from Application

application_classes, find_application_class_for, #find_executable, inherited, #my_os, #my_os_family, #run

Constructor Details

#initializeBrowser

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)

Returns:

  • (Boolean)


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

.run(*args) ⇒ Object



14
15
16
# File 'lib/launchy/spawnable/browser.rb', line 14

def run(*args)
    Browser.new.visit(args[0]) 
end

Instance Method Details

#app_listObject

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

#browserObject

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