Class: ValidateWebsite::Core

Inherits:
Object
  • Object
show all
Includes:
ColorfulMessages
Defined in:
lib/validate_website/core.rb

Overview

Core class for static or website validation

Direct Known Subclasses

Crawl, Static

Constant Summary collapse

EXIT_SUCCESS =
0
EXIT_FAILURE_MARKUP =
64
EXIT_FAILURE_NOT_FOUND =
65
EXIT_FAILURE_MARKUP_NOT_FOUND =
66

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ColorfulMessages

#color, #error, #info, #note, #success, #warning

Constructor Details

#initialize(options, validation_type) ⇒ NilClass

Initialize core ValidateWebsite class

Examples:

new({ site: "https://example.com/" }, :crawl)

Parameters:

  • options (Hash)


35
36
37
38
39
40
41
42
43
# File 'lib/validate_website/core.rb', line 35

def initialize(options, validation_type)
  @not_founds_count = 0
  @errors_count = 0
  @options = Parser.parse(options, validation_type).to_h
  @site = @options[:site]
  @service_url = @options[:html5_validator_service_url]
  Validator.html5_validator_service_url = @service_url if @service_url
  puts color(:note, "validating #{@site}\n", @options[:color])
end

Instance Attribute Details

#errors_countObject (readonly)

Returns the value of attribute errors_count.



21
22
23
# File 'lib/validate_website/core.rb', line 21

def errors_count
  @errors_count
end

#hostObject (readonly)

Returns the value of attribute host.



21
22
23
# File 'lib/validate_website/core.rb', line 21

def host
  @host
end

#not_founds_countObject (readonly)

Returns the value of attribute not_founds_count.



21
22
23
# File 'lib/validate_website/core.rb', line 21

def not_founds_count
  @not_founds_count
end

#optionsObject (readonly)

Returns the value of attribute options.



21
22
23
# File 'lib/validate_website/core.rb', line 21

def options
  @options
end

#siteObject

Returns the value of attribute site.



20
21
22
# File 'lib/validate_website/core.rb', line 20

def site
  @site
end

Instance Method Details

#default_cookiesObject



65
66
67
68
69
70
# File 'lib/validate_website/core.rb', line 65

def default_cookies
  WEBrick::Cookie.parse(@options[:cookies]).each_with_object({}) do |c, h|
    h[c.name] = c.value
    h
  end
end

#errors?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/validate_website/core.rb', line 45

def errors?
  @errors_count > 0
end

#exit_statusObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/validate_website/core.rb', line 53

def exit_status
  if errors? && not_founds?
    EXIT_FAILURE_MARKUP_NOT_FOUND
  elsif errors?
    EXIT_FAILURE_MARKUP
  elsif not_founds?
    EXIT_FAILURE_NOT_FOUND
  else
    EXIT_SUCCESS
  end
end

#not_founds?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/validate_website/core.rb', line 49

def not_founds?
  @not_founds_count > 0
end