Class: StaticLink

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

Returns the value of attribute link

Returns:

  • (Object)

    the current value of link



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

def link
  @link
end

#siteObject

Returns the value of attribute site

Returns:

  • (Object)

    the current value of site



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

def site
  @site
end

Instance Method Details

#bodyObject



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

Returns:

  • (Boolean)


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

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

#content_typesObject



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

Returns:

  • (Boolean)


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

def css?
  extname == '.css'
end

#extnameObject



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_responseObject



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_pathObject



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

Returns:

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


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

#pageObject



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

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

#responseObject



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