Class: StaticLink
- Inherits:
-
Struct
- Object
- Struct
- StaticLink
- Defined in:
- lib/validate_website/static_link.rb
Overview
rubocop:disable Metrics/BlockLength
Instance Attribute Summary collapse
-
#link ⇒ Object
Returns the value of attribute link.
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
- #body ⇒ Object
- #check? ⇒ Boolean
- #content_types ⇒ Object
- #css? ⇒ Boolean
- #extname ⇒ Object
- #extract_urls_from_fake_css_response ⇒ Object
- #file_path ⇒ Object
- #in_static_domain? ⇒ Boolean
- #link_uri ⇒ Object
- #page ⇒ Object
- #response ⇒ Object
Instance Attribute Details
#link ⇒ Object
Returns the value of attribute link
9 10 11 |
# File 'lib/validate_website/static_link.rb', line 9 def link @link end |
#site ⇒ Object
Returns the value of attribute site
9 10 11 |
# File 'lib/validate_website/static_link.rb', line 9 def site @site end |
Instance Method Details
#body ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/validate_website/static_link.rb', line 28 def body if File.exist?(link) File.open(link).read else File.open(file_path).read end end |
#check? ⇒ Boolean
65 66 67 |
# File 'lib/validate_website/static_link.rb', line 65 def check? !link.include?('#') && in_static_domain? end |
#content_types ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/validate_website/static_link.rb', line 20 def content_types if css? ['text/css'] else ValidateWebsite::Static::CONTENT_TYPES end end |
#css? ⇒ Boolean
61 62 63 |
# File 'lib/validate_website/static_link.rb', line 61 def css? extname == '.css' end |
#extname ⇒ Object
57 58 59 |
# File 'lib/validate_website/static_link.rb', line 57 def extname @extname ||= File.extname(file_path) end |
#extract_urls_from_fake_css_response ⇒ Object
47 48 49 |
# File 'lib/validate_website/static_link.rb', line 47 def extract_urls_from_fake_css_response ValidateWebsite::Utils.extract_urls_from_css(page) end |
#file_path ⇒ Object
51 52 53 54 55 |
# File 'lib/validate_website/static_link.rb', line 51 def file_path @file_path ||= URI.parse( File.join(Dir.getwd, link_uri.path || '/') ).path end |
#in_static_domain? ⇒ Boolean
16 17 18 |
# File 'lib/validate_website/static_link.rb', line 16 def in_static_domain? URI.parse(site).host == link_uri.host end |
#link_uri ⇒ Object
10 11 12 13 14 |
# File 'lib/validate_website/static_link.rb', line 10 def link_uri @link_uri = URI.parse(WEBrick::HTTPUtils.escape(link)) @link_uri = URI.join(site, @link_uri) if @link_uri.host.nil? @link_uri end |
#page ⇒ Object
43 44 45 |
# File 'lib/validate_website/static_link.rb', line 43 def page @page ||= Spidr::Page.new(link_uri, response) end |
#response ⇒ Object
36 37 38 39 40 41 |
# File 'lib/validate_website/static_link.rb', line 36 def response @response ||= ValidateWebsite::Static.fake_httpresponse( body, content_types ) end |