Class: W3Clove::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/w3clove/page.rb

Overview

A page has an URL to be validated, and a collection of errors In case of an exception happens when validating, it is tracked

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, timeout = 20) ⇒ Page

Returns a new instance of Page.



15
16
17
18
# File 'lib/w3clove/page.rb', line 15

def initialize(url, timeout = 20)
  @url      = url
  @timeout  = timeout
end

Instance Attribute Details

#exceptionObject

Returns the value of attribute exception.



13
14
15
# File 'lib/w3clove/page.rb', line 13

def exception
  @exception
end

#timeoutObject

Returns the value of attribute timeout.



13
14
15
# File 'lib/w3clove/page.rb', line 13

def timeout
  @timeout
end

#urlObject

Returns the value of attribute url.



13
14
15
# File 'lib/w3clove/page.rb', line 13

def url
  @url
end

Instance Method Details

#errorsObject

Returns the collection of errors from the validations of this page. If it has no validation errors, it will be an empty array. It an exception occurs, it will be nil.



34
35
36
37
38
39
40
41
42
43
# File 'lib/w3clove/page.rb', line 34

def errors
  @errors ||= validations.errors
                .select {|e| e.message_id && !e.message_id.empty?}
                .map do |e|
    W3Clove::Message.new(e.message_id, e.line, e.message, :error)
  end
rescue Exception => e
  @exception = e.to_s
  nil
end

#valid?Boolean

Checks for errors and returns true if none found, false otherwise. Warnings are not considered as validation errors so a page with warnings but without errors will return true. If the validation goes well, errors should be an array. Otherwise it will still be nil, which will not be considered validated.

Returns:

  • (Boolean)


26
27
28
# File 'lib/w3clove/page.rb', line 26

def valid?
  !errors.nil? && errors.empty?
end

#warningsObject

Returns the collection of warnings from the validations of this page. If it has no validation warnings, it will be an empty array. It an exception occurs, it will be nil.



49
50
51
52
53
54
55
56
57
58
# File 'lib/w3clove/page.rb', line 49

def warnings
  @warnings ||= validations.warnings
                 .select {|w| w.message_id && !w.message_id.empty?}
                 .map do |w|
    W3Clove::Message.new(w.message_id, w.line, w.message, :warning)
  end
rescue Exception => e
  @exception = e.to_s
  nil
end