Class: Adva::Static::Export::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/adva/static/export/page.rb

Constant Summary collapse

URL_ATTRIBUTES =
{
  '//a[@href]' => 'href',
  '//script[@src]' => 'src',
  '//link[@rel="stylesheet"]' => 'href'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, response) ⇒ Page

Returns a new instance of Page.



15
16
17
18
# File 'lib/adva/static/export/page.rb', line 15

def initialize(url, response)
  @url      = Path.new(url)
  @response = response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



13
14
15
# File 'lib/adva/static/export/page.rb', line 13

def response
  @response
end

#urlObject (readonly)

Returns the value of attribute url.



13
14
15
# File 'lib/adva/static/export/page.rb', line 13

def url
  @url
end

Instance Method Details

#bodyObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/adva/static/export/page.rb', line 26

def body
  @body ||= case response
  when ActionDispatch::Response
    response.body
  when ::Rack::File
    File.read(response.path)
  else
    response.to_s
  end
end

#urlsObject



20
21
22
23
24
# File 'lib/adva/static/export/page.rb', line 20

def urls
  URL_ATTRIBUTES.inject([]) do |urls, (xpath, name)|
    urls += dom.xpath(xpath).map { |node| Path.new(node.attributes[name]) }
  end
end