Class: StaticLink
- Inherits:
-
Struct
- Object
- Struct
- StaticLink
- Defined in:
- lib/validate_website/static_link.rb
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
6 7 8 |
# File 'lib/validate_website/static_link.rb', line 6 def link @link end |
#site ⇒ Object
Returns the value of attribute site
6 7 8 |
# File 'lib/validate_website/static_link.rb', line 6 def site @site end |
Instance Method Details
#body ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/validate_website/static_link.rb', line 25 def body if File.exist?(link) open(link).read else open(file_path).read end end |
#check? ⇒ Boolean
62 63 64 |
# File 'lib/validate_website/static_link.rb', line 62 def check? !link.include?('#') && in_static_domain? end |
#content_types ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/validate_website/static_link.rb', line 17 def content_types if css? ['text/css'] else ValidateWebsite::Static::CONTENT_TYPES end end |
#css? ⇒ Boolean
58 59 60 |
# File 'lib/validate_website/static_link.rb', line 58 def css? extname == '.css' end |
#extname ⇒ Object
54 55 56 |
# File 'lib/validate_website/static_link.rb', line 54 def extname @extname ||= File.extname(file_path) end |
#extract_urls_from_fake_css_response ⇒ Object
44 45 46 |
# File 'lib/validate_website/static_link.rb', line 44 def extract_urls_from_fake_css_response ValidateWebsite::Utils.extract_urls_from_css(page) end |
#file_path ⇒ Object
48 49 50 51 52 |
# File 'lib/validate_website/static_link.rb', line 48 def file_path @file_path ||= URI.parse( File.join(Dir.getwd, link_uri.path || '/') ).path end |
#in_static_domain? ⇒ Boolean
13 14 15 |
# File 'lib/validate_website/static_link.rb', line 13 def in_static_domain? URI.parse(site).host == link_uri.host end |
#link_uri ⇒ Object
7 8 9 10 11 |
# File 'lib/validate_website/static_link.rb', line 7 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
40 41 42 |
# File 'lib/validate_website/static_link.rb', line 40 def page @page ||= Spidr::Page.new(link_uri, response) end |
#response ⇒ Object
33 34 35 36 37 38 |
# File 'lib/validate_website/static_link.rb', line 33 def response @response ||= ValidateWebsite::Static.fake_httpresponse( body, content_types ) end |