Class: Botz::Connector::Html
- Inherits:
-
Object
- Object
- Botz::Connector::Html
- Includes:
- Field
- Defined in:
- lib/botz/connector/html.rb
Overview
Mechanize wrapper
Defined Under Namespace
Modules: Field
Constant Summary collapse
- USER_AGENT =
[ 'Mozilla/5.0', '(Macintosh; Intel Mac OS X 10_12_6)', 'AppleWebKit/537.36', '(KHTML, like Gecko)', 'Chrome/64.0.3282.186', 'Safari/537.36' ].join(' ')
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#start_url ⇒ Object
readonly
Returns the value of attribute start_url.
Instance Method Summary collapse
- #call(url = @start_url, &block) ⇒ Object
-
#initialize(start_url: nil, encoding: nil) ⇒ Html
constructor
A new instance of Html.
Methods included from Field
Constructor Details
#initialize(start_url: nil, encoding: nil) ⇒ Html
Returns a new instance of Html.
33 34 35 36 37 38 39 40 41 |
# File 'lib/botz/connector/html.rb', line 33 def initialize(start_url: nil, encoding: nil) @start_url = start_url @agent = Mechanize.new if encoding @agent.default_encoding = encoding @agent.force_default_encoding = true end @agent.user_agent = USER_AGENT end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
31 32 33 |
# File 'lib/botz/connector/html.rb', line 31 def agent @agent end |
#start_url ⇒ Object (readonly)
Returns the value of attribute start_url.
30 31 32 |
# File 'lib/botz/connector/html.rb', line 30 def start_url @start_url end |
Instance Method Details
#call(url = @start_url, &block) ⇒ Object
43 44 45 46 47 |
# File 'lib/botz/connector/html.rb', line 43 def call(url = @start_url, &block) fail 'URL is undefined' if url.blank? agent.get(url, &block) end |