Class: Makuri::Browser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Browser

Returns a new instance of Browser.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/makuri/browser.rb', line 5

def initialize(options = {})
  @current_url    = options.fetch(:url, '')
  @request_method = options.fetch(:request_method, :get)
  @request_body   = options.fetch(:request_body, {})

  @render_js      = options.fetch(:render_js, false)
  @user_agent     = options.fetch(
    :user_agent,
    'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36'
  )
end

Instance Attribute Details

#current_urlObject

Returns the value of attribute current_url.



3
4
5
# File 'lib/makuri/browser.rb', line 3

def current_url
  @current_url
end

#render_jsObject

Returns the value of attribute render_js.



3
4
5
# File 'lib/makuri/browser.rb', line 3

def render_js
  @render_js
end

#request_bodyObject

Returns the value of attribute request_body.



3
4
5
# File 'lib/makuri/browser.rb', line 3

def request_body
  @request_body
end

#request_methodObject

Returns the value of attribute request_method.



3
4
5
# File 'lib/makuri/browser.rb', line 3

def request_method
  @request_method
end

#user_agentObject

Returns the value of attribute user_agent.



3
4
5
# File 'lib/makuri/browser.rb', line 3

def user_agent
  @user_agent
end

Instance Method Details

#follow(url = '') ⇒ Object



17
18
19
20
21
22
23
# File 'lib/makuri/browser.rb', line 17

def follow(url = '')
  @current_url = url unless url.empty?
  raise 'Invalid URL supplied' if @current_url.empty?

  @browser = create_browser
  @browser.visit(@current_url)
end