Class: Spidy::Connector::Html
- Inherits:
-
Object
- Object
- Spidy::Connector::Html
- Includes:
- StaticAccessor
- Defined in:
- lib/spidy/connector/html.rb
Overview
Mechanize wrapper
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
Instance Method Summary collapse
- #call(url, encoding: nil, &yielder) ⇒ Object
-
#initialize(user_agent:) ⇒ Html
constructor
A new instance of Html.
- #refresh! ⇒ Object
Constructor Details
#initialize(user_agent:) ⇒ Html
Returns a new instance of Html.
7 8 9 10 11 |
# File 'lib/spidy/connector/html.rb', line 7 def initialize(user_agent:) @agent = Mechanize.new @user_agent = user_agent @agent.user_agent = user_agent end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
13 14 15 |
# File 'lib/spidy/connector/html.rb', line 13 def agent @agent end |
Instance Method Details
#call(url, encoding: nil, &yielder) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/spidy/connector/html.rb', line 15 def call(url, encoding: nil, &yielder) fail 'url is not specified' if url.blank? if encoding agent.default_encoding = encoding agent.force_default_encoding = true end connect(url, yielder) end |
#refresh! ⇒ Object
24 25 26 27 |
# File 'lib/spidy/connector/html.rb', line 24 def refresh! @agent = Mechanize.new @agent.user_agent = @user_agent end |