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
7 8 9 |
# File 'lib/validate_website/static_link.rb', line 7 def link @link end |
#site ⇒ Object
Returns the value of attribute site
7 8 9 |
# File 'lib/validate_website/static_link.rb', line 7 def site @site end |
Instance Method Details
#body ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/validate_website/static_link.rb', line 26 def body if File.exist?(link) open(link).read else open(file_path).read end end |
#check? ⇒ Boolean
63 64 65 |
# File 'lib/validate_website/static_link.rb', line 63 def check? !link.include?('#') && in_static_domain? end |
#content_types ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/validate_website/static_link.rb', line 18 def content_types if css? ['text/css'] else ValidateWebsite::Static::CONTENT_TYPES end end |
#css? ⇒ Boolean
59 60 61 |
# File 'lib/validate_website/static_link.rb', line 59 def css? extname == '.css' end |
#extname ⇒ Object
55 56 57 |
# File 'lib/validate_website/static_link.rb', line 55 def extname @extname ||= File.extname(file_path) end |
#extract_urls_from_fake_css_response ⇒ Object
45 46 47 |
# File 'lib/validate_website/static_link.rb', line 45 def extract_urls_from_fake_css_response ValidateWebsite::Utils.extract_urls_from_css(page) end |
#file_path ⇒ Object
49 50 51 52 53 |
# File 'lib/validate_website/static_link.rb', line 49 def file_path @file_path ||= URI.parse( File.join(Dir.getwd, link_uri.path || '/') ).path end |
#in_static_domain? ⇒ Boolean
14 15 16 |
# File 'lib/validate_website/static_link.rb', line 14 def in_static_domain? URI.parse(site).host == link_uri.host end |
#link_uri ⇒ Object
8 9 10 11 12 |
# File 'lib/validate_website/static_link.rb', line 8 def link_uri @link_uri = URI.parse(URI.encode(link)) @link_uri = URI.join(site, @link_uri) if @link_uri.host.nil? @link_uri end |
#page ⇒ Object
41 42 43 |
# File 'lib/validate_website/static_link.rb', line 41 def page @page ||= Spidr::Page.new(link_uri, response) end |
#response ⇒ Object
34 35 36 37 38 39 |
# File 'lib/validate_website/static_link.rb', line 34 def response @response ||= ValidateWebsite::Static.fake_httpresponse( body, content_types ) end |