Class: RelatonAsme::Fetcher::BasicPage

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_asme/fetcher/basic_page.rb

Overview

Base class for web scraping pages using Mechanize

Direct Known Subclasses

IndexPage, PublicationPage

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#agentObject (readonly)

Returns the value of attribute agent.



9
10
11
# File 'lib/relaton_asme/fetcher/basic_page.rb', line 9

def agent
  @agent
end

#pageObject (readonly)

Returns the value of attribute page.



9
10
11
# File 'lib/relaton_asme/fetcher/basic_page.rb', line 9

def page
  @page
end

#urlObject (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_pageMechanize::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

#fetchMechanize::Page

Fetch the page



24
25
26
# File 'lib/relaton_asme/fetcher/basic_page.rb', line 24

def fetch
  @page = @agent.get(url)
end