Class: StaticLink

Inherits:
Struct
  • Object
show all
Defined in:
lib/validate_website/static_link.rb

Overview

rubocop:disable Metrics/BlockLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

Returns the value of attribute link

Returns:

  • (Object)

    the current value of link



7
8
9
# File 'lib/validate_website/static_link.rb', line 7

def link
  @link
end

#siteObject

Returns the value of attribute site

Returns:

  • (Object)

    the current value of site



7
8
9
# File 'lib/validate_website/static_link.rb', line 7

def site
  @site
end

Instance Method Details

#bodyObject



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

Returns:

  • (Boolean)


63
64
65
# File 'lib/validate_website/static_link.rb', line 63

def check?
  !link.include?('#') && in_static_domain?
end

#content_typesObject



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

Returns:

  • (Boolean)


59
60
61
# File 'lib/validate_website/static_link.rb', line 59

def css?
  extname == '.css'
end

#extnameObject



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_responseObject



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_pathObject



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

Returns:

  • (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


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

#pageObject



41
42
43
# File 'lib/validate_website/static_link.rb', line 41

def page
  @page ||= Spidr::Page.new(link_uri, response)
end

#responseObject



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