Class: ValidateWebsite::Parser

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

Overview

Internal class for parse command line args

Constant Summary collapse

DEFAULT_OPTIONS =
{
  markup: true,
  # crawler: log not found url (404 status code)
  # static: log not found url (not on filesystem, `pwd` considered
  # as root « / »)
  not_found: false,
  file: nil,
  # regex to ignore certain validation errors
  ignore: nil,
  color: true,
  # internal verbose for ValidateWebsite
  verbose: false,
}
DEFAULT_OPTIONS_CRAWL =
{
  site: 'http://localhost:3000/',
  exclude: nil,
  user_agent: nil,
}.merge(DEFAULT_OPTIONS)
DEFAULT_OPTIONS_STATIC =
{
  site: 'http://www.example.com/',
  pattern: '**/*.html',
}.merge(DEFAULT_OPTIONS)

Class Method Summary collapse

Class Method Details

.command_line_parse_crawl(_args) ⇒ Hash

Parse command line for validate-website bin

Returns:

  • (Hash)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/validate_website/option_parser.rb', line 45

def self.command_line_parse_crawl(_args)
  Slop.parse(help: true) do
    banner 'Usage: validate-website [OPTIONS]'

    on("s", "site=", "Website to crawl",
       default: DEFAULT_OPTIONS_CRAWL[:site])
    on(:u, :user_agent=, "Change user agent",
       default: DEFAULT_OPTIONS_CRAWL[:user_agent])
    on("e", "exclude=", "Url to exclude (ex: 'redirect|news')",
       type: :regexp)
    on("c", "cookies=", "Set defaults cookies")
    on("m", "markup", "Markup validation",
       default: DEFAULT_OPTIONS_CRAWL[:markup])
    on("i", "ignore=", "Validation errors to ignore",
       type: :regexp)
    on(:n, :not_found, "Log not found url",
       default: DEFAULT_OPTIONS_CRAWL[:not_found])
    on("color", "Show colored output",
       default: DEFAULT_OPTIONS_CRAWL[:color])
    on("v", "verbose", "Show validator errors",
       default: DEFAULT_OPTIONS_CRAWL[:verbose])
  end
end

.command_line_parse_static(_args) ⇒ Hash

Parse command line for validate-website-static bin

Returns:

  • (Hash)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/validate_website/option_parser.rb', line 72

def self.command_line_parse_static(_args)
  Slop.parse(help: true) do
    banner 'Usage: validate-website-static [OPTIONS]'

    on("s", "site=", "Website to crawl",
       default: DEFAULT_OPTIONS_STATIC[:site])
    on("p", "pattern=", "Change filenames pattern",
       type: :regexp, default: DEFAULT_OPTIONS_STATIC[:pattern])
    on("c", "cookies=", "Set defaults cookies")
    on("m", "markup", "Markup validation",
       default: DEFAULT_OPTIONS_STATIC[:markup])
    on("i", "ignore=", "Validation errors to ignore",
       type: :regexp)
    on(:n, :not_found, "Log not found url",
       default: DEFAULT_OPTIONS_STATIC[:not_found])
    on("color", "Show colored output",
       default: DEFAULT_OPTIONS_STATIC[:color])
    on("v", "verbose", "Show validator errors",
       default: DEFAULT_OPTIONS_STATIC[:verbose])
  end
end

.parse(options, type) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/validate_website/option_parser.rb', line 32

def self.parse(options, type)
  const = "DEFAULT_OPTIONS_#{type.to_s.upcase}"
  fail ArgumentError unless const_defined?(const)
  if Array === options
    send("command_line_parse_#{type}", options)
  else
    const_get(const).merge(options)
  end
end