Class: SiteInspector::Endpoint::Content

Inherits:
Check
  • Object
show all
Defined in:
lib/site-inspector/checks/content.rb

Instance Attribute Summary

Attributes inherited from Check

#endpoint

Instance Method Summary collapse

Methods inherited from Check

#host, #initialize, #inspect, #name, name, #request, #response

Constructor Details

This class inherits a constructor from SiteInspector::Endpoint::Check

Instance Method Details

#bodyObject



15
16
17
# File 'lib/site-inspector/checks/content.rb', line 15

def body
  @body ||= document.to_s.force_encoding("UTF-8").encode("UTF-8", :invalid => :replace, :replace => "")
end

#doctypeObject



31
32
33
# File 'lib/site-inspector/checks/content.rb', line 31

def doctype
  document.internal_subset.name
end

#documentObject Also known as: doc



9
10
11
12
# File 'lib/site-inspector/checks/content.rb', line 9

def document
  require 'nokogiri'
  @doc ||= Nokogiri::HTML response.body if response
end

#humans_txt?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/site-inspector/checks/content.rb', line 27

def humans_txt?
  @humans_txt ||= path_exists?("humans.txt")
end

#path_exists?(path) ⇒ Boolean

Given a path (e.g, “/data”), check if the given path exists on the canonical endpoint

Returns:

  • (Boolean)


5
6
7
# File 'lib/site-inspector/checks/content.rb', line 5

def path_exists?(path)
  endpoint.request(path: path, followlocation: true).success?
end

#prefetchObject



35
36
37
38
39
40
41
42
# File 'lib/site-inspector/checks/content.rb', line 35

def prefetch
  options = SiteInspector.typhoeus_defaults.merge(followlocation: true)
  ["robots.txt", "sitemap.xml", "humans.txt", random_path].each do |path|
    request = Typhoeus::Request.new(URI.join(endpoint.uri, path), options)
    SiteInspector.hydra.queue(request)
  end
  SiteInspector.hydra.run
end

#proper_404s?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/site-inspector/checks/content.rb', line 44

def proper_404s?
  @proper_404s ||= !path_exists?(random_path)
end

#robots_txt?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/site-inspector/checks/content.rb', line 19

def robots_txt?
  @bodts_txt ||= path_exists?("robots.txt")
end

#sitemap_xml?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/site-inspector/checks/content.rb', line 23

def sitemap_xml?
  @sitemap_xml ||= path_exists?("sitemap.xml")
end

#to_hObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/site-inspector/checks/content.rb', line 48

def to_h
  prefetch
  {
    doctype:     doctype,
    sitemap_xml: sitemap_xml?,
    robots_txt:  robots_txt?,
    humans_txt:  humans_txt?,
    proper_404s: proper_404s?
  }
end