Class: Browser

Inherits:
Object
  • Object
show all
Defined in:
lib/zfben_hanoi/browser.rb

Direct Known Subclasses

Chromium, Firefox

Instance Method Summary collapse

Instance Method Details

#escaped_nameObject



50
51
52
# File 'lib/zfben_hanoi/browser.rb', line 50

def escaped_name
  name.gsub(' ', '\ ')
end

#hostObject



6
7
8
9
# File 'lib/zfben_hanoi/browser.rb', line 6

def host
  require 'rbconfig'
  Config::CONFIG['host']
end

#installed?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/zfben_hanoi/browser.rb', line 23

def installed?
  if linux?
    Kernel.system "which #{name}"
  else
    File.exist? path
  end
end

#linux?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/zfben_hanoi/browser.rb', line 19

def linux?
  host.include?('linux')
end

#macos?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/zfben_hanoi/browser.rb', line 11

def macos?
  host.include?('darwin')
end

#nameObject



45
46
47
48
# File 'lib/zfben_hanoi/browser.rb', line 45

def name
  n = self.class.name.split('::').last
  linux? ? n.downcase : n
end

#pathObject



54
55
56
57
58
59
60
# File 'lib/zfben_hanoi/browser.rb', line 54

def path
  if macos?
    File.expand_path("/Applications/#{escaped_name}.app")
  else
    @path
  end
end

#runnable?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/zfben_hanoi/browser.rb', line 31

def runnable?
  supported? && installed?
end

#setupObject



3
# File 'lib/zfben_hanoi/browser.rb', line 3

def setup; end

#supported?Boolean

Returns:

  • (Boolean)


2
# File 'lib/zfben_hanoi/browser.rb', line 2

def supported?; true; end

#teardownObject



4
# File 'lib/zfben_hanoi/browser.rb', line 4

def teardown; end

#to_sObject



62
63
64
# File 'lib/zfben_hanoi/browser.rb', line 62

def to_s
  name
end

#visit(url) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/zfben_hanoi/browser.rb', line 35

def visit(url)
  if macos?
    system("open -g -a #{path} '#{url}'")
  elsif windows?
    system("#{path} #{url}")
  elsif linux?
    system("#{name} #{url}")
  end
end

#windows?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/zfben_hanoi/browser.rb', line 15

def windows?
  /mswin|mingw/.match host
end