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
START_MESSAGE =
'Validating'

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)
  • validation_type (Symbol)

    `crawl` for web or `static` for local


39
40
41
42
43
44
45
46
# File 'lib/validate_website/core.rb', line 39

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
end

Instance Attribute Details

#errors_countObject (readonly)

Returns the value of attribute errors_count


23
24
25
# File 'lib/validate_website/core.rb', line 23

def errors_count
  @errors_count
end

#hostObject (readonly)

Returns the value of attribute host


23
24
25
# File 'lib/validate_website/core.rb', line 23

def host
  @host
end

#not_founds_countObject (readonly)

Returns the value of attribute not_founds_count


23
24
25
# File 'lib/validate_website/core.rb', line 23

def not_founds_count
  @not_founds_count
end

#optionsObject (readonly)

Returns the value of attribute options


23
24
25
# File 'lib/validate_website/core.rb', line 23

def options
  @options
end

#siteObject

Returns the value of attribute site


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

def site
  @site
end

Instance Method Details

#default_cookiesObject


68
69
70
71
72
73
# File 'lib/validate_website/core.rb', line 68

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)

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

def errors?
  @errors_count.positive?
end

#exit_statusObject


56
57
58
59
60
61
62
63
64
65
66
# File 'lib/validate_website/core.rb', line 56

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)

52
53
54
# File 'lib/validate_website/core.rb', line 52

def not_founds?
  @not_founds_count.positive?
end