Class: Botz::ResourceAccessor::Html
- Inherits:
-
Object
- Object
- Botz::ResourceAccessor::Html
- Defined in:
- lib/botz/resource_accessor/html.rb
Overview
Mechanize wrapper
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.
Constructor Details
#initialize(start_url: nil, encoding: nil) ⇒ Html
Returns a new instance of Html.
19 20 21 22 23 24 25 26 27 |
# File 'lib/botz/resource_accessor/html.rb', line 19 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.
17 18 19 |
# File 'lib/botz/resource_accessor/html.rb', line 17 def agent @agent end |
#start_url ⇒ Object (readonly)
Returns the value of attribute start_url.
16 17 18 |
# File 'lib/botz/resource_accessor/html.rb', line 16 def start_url @start_url end |
Instance Method Details
#call(url = @start_url, &block) ⇒ Object
29 30 31 32 33 |
# File 'lib/botz/resource_accessor/html.rb', line 29 def call(url = @start_url, &block) fail 'URL is undefined' if url.blank? agent.get(url, &block) end |