class Vnu

Ruby wrapper for [vnu](validator.github.io/validator/)

Constants

JAR_PATH

Attributes

command[R]
target[R]

Public Class Methods

cli() click to toggle source
# File lib/vnu.rb, line 28
def cli
  @cli ||= "java -jar #{JAR_PATH}"
end
cli_version() click to toggle source
# File lib/vnu.rb, line 32
def cli_version
  @cli_version ||= `#{cli} --version`.chomp
end
new(*options) click to toggle source
# File lib/vnu.rb, line 9
def initialize(*options)
  @target = options.shift
  options = options.last
  if target
    @command = vnu_cli_with_options(options)
  else
    fail RuntimeError
  end
end
validate(*options) click to toggle source
# File lib/vnu.rb, line 36
def validate(*options)
  new(*options).validate
end

Public Instance Methods

validate() click to toggle source
# File lib/vnu.rb, line 23
def validate
  execute(command)
end
vnu_cli_with_options(options) click to toggle source
# File lib/vnu.rb, line 19
def vnu_cli_with_options(options)
  "#{self.class.cli}#{vnu_options(options)} -"
end

Private Instance Methods

execute(command) click to toggle source
# File lib/vnu.rb, line 52
def execute(command)
  @output = @error = @exit_status = nil
  Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
    stdin.puts target
    stdin.close
    @output = stdout.read.chomp
    @error = stderr.read.chomp
    @exit_status = wait_thr.value
  end
  @error unless @exit_status.success?
end
vnu_options(options) click to toggle source
# File lib/vnu.rb, line 43
def vnu_options(options)
  return unless options
  return @vnu_options if @vnu_options
  @vnu_options = options.each_with_object('') do |o, str|
    k = o.last.is_a?(String) ? " #{o.last}" : nil
    str << " --#{o.first.to_s.gsub(/_/, '-')}#{k}"
  end
end