Class: RelatonAsme::Fetcher::BasicPage
- Inherits:
-
Object
- Object
- RelatonAsme::Fetcher::BasicPage
- Defined in:
- lib/relaton_asme/fetcher/basic_page.rb
Overview
Base class for web scraping pages using Mechanize
Direct Known Subclasses
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#ensure_page ⇒ Mechanize::Page
Get the page, fetching if necessary.
-
#fetch ⇒ Mechanize::Page
Fetch the page.
-
#initialize(url, agent: nil) ⇒ BasicPage
constructor
Initialize a new page fetcher.
Constructor Details
#initialize(url, agent: nil) ⇒ BasicPage
Initialize a new page fetcher
15 16 17 18 19 |
# File 'lib/relaton_asme/fetcher/basic_page.rb', line 15 def initialize(url, agent: nil) @url = url @agent = agent || create_agent @page = nil end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
9 10 11 |
# File 'lib/relaton_asme/fetcher/basic_page.rb', line 9 def agent @agent end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
9 10 11 |
# File 'lib/relaton_asme/fetcher/basic_page.rb', line 9 def page @page end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/relaton_asme/fetcher/basic_page.rb', line 9 def url @url end |
Instance Method Details
#ensure_page ⇒ Mechanize::Page
Get the page, fetching if necessary
31 32 33 |
# File 'lib/relaton_asme/fetcher/basic_page.rb', line 31 def ensure_page @ensure_page ||= fetch end |
#fetch ⇒ Mechanize::Page
Fetch the page
24 25 26 |
# File 'lib/relaton_asme/fetcher/basic_page.rb', line 24 def fetch @page = @agent.get(url) end |