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


9
10
11
# File 'lib/validate_website/static_link.rb', line 9

def link
  @link
end

#siteObject

Returns the value of attribute site

Returns:

  • (Object)

    the current value of site


9
10
11
# File 'lib/validate_website/static_link.rb', line 9

def site
  @site
end

Instance Method Details

#bodyObject


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

Returns:

  • (Boolean)

65
66
67
# File 'lib/validate_website/static_link.rb', line 65

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

#content_typesObject


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

Returns:

  • (Boolean)

61
62
63
# File 'lib/validate_website/static_link.rb', line 61

def css?
  extname == '.css'
end

#extnameObject


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_responseObject


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_pathObject


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

Returns:

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

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

#pageObject


43
44
45
# File 'lib/validate_website/static_link.rb', line 43

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

#responseObject


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