Class: Ferrum::Browser::Command
- Inherits:
-
Object
- Object
- Ferrum::Browser::Command
- Defined in:
- lib/ferrum/browser/command.rb
Constant Summary collapse
- NOT_FOUND =
"Could not find an executable for the browser. Try to make " \ "it available on the PATH or set environment variable for " \ "example BROWSER_PATH=\"/usr/bin/chrome\""
Instance Attribute Summary collapse
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.build(options, user_data_dir) ⇒ Object
Currently only these browsers support CDP: github.com/cyrus-and/chrome-remote-interface#implementations.
Instance Method Summary collapse
-
#initialize(defaults, options, user_data_dir) ⇒ Command
constructor
A new instance of Command.
- #to_a ⇒ Object
- #to_s ⇒ Object
- #xvfb? ⇒ Boolean
Constructor Details
#initialize(defaults, options, user_data_dir) ⇒ Command
Returns a new instance of Command.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ferrum/browser/command.rb', line 27 def initialize(defaults, , user_data_dir) @flags = {} @defaults = defaults = @user_data_dir = user_data_dir @path = .browser_path || ENV.fetch("BROWSER_PATH", nil) || defaults.detect_path raise BinaryNotFoundError, NOT_FOUND unless @path end |
Instance Attribute Details
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
25 26 27 |
# File 'lib/ferrum/browser/command.rb', line 25 def defaults @defaults end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
25 26 27 |
# File 'lib/ferrum/browser/command.rb', line 25 def end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
25 26 27 |
# File 'lib/ferrum/browser/command.rb', line 25 def path @path end |
Class Method Details
.build(options, user_data_dir) ⇒ Object
Currently only these browsers support CDP: github.com/cyrus-and/chrome-remote-interface#implementations
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ferrum/browser/command.rb', line 12 def self.build(, user_data_dir) defaults = case .browser_name when :firefox Options::Firefox. when :chrome, :opera, :edge, nil Options::Chrome. else raise NotImplementedError, "not supported browser" end new(defaults, , user_data_dir) end |
Instance Method Details
#to_a ⇒ Object
42 43 44 |
# File 'lib/ferrum/browser/command.rb', line 42 def to_a [path] + @flags.map { |k, v| v.nil? ? "--#{k}" : "--#{k}=#{v}" } end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/ferrum/browser/command.rb', line 46 def to_s to_a.join(" \\ \n ") end |
#xvfb? ⇒ Boolean
38 39 40 |
# File 'lib/ferrum/browser/command.rb', line 38 def xvfb? !!.xvfb end |