Class: W3Clove::Page
- Inherits:
-
Object
- Object
- W3Clove::Page
- 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
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#errors ⇒ Object
Returns the collection of errors from the validations of this page.
-
#initialize(url, timeout = 20) ⇒ Page
constructor
A new instance of Page.
-
#valid? ⇒ Boolean
Checks for errors and returns true if none found, false otherwise.
-
#warnings ⇒ Object
Returns the collection of warnings from the validations of this page.
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
#exception ⇒ Object
Returns the value of attribute exception.
13 14 15 |
# File 'lib/w3clove/page.rb', line 13 def exception @exception end |
#timeout ⇒ Object
Returns the value of attribute timeout.
13 14 15 |
# File 'lib/w3clove/page.rb', line 13 def timeout @timeout end |
#url ⇒ Object
Returns the value of attribute url.
13 14 15 |
# File 'lib/w3clove/page.rb', line 13 def url @url end |
Instance Method Details
#errors ⇒ Object
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. && !e..empty?} .map do |e| W3Clove::Message.new(e., e.line, e., :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.
26 27 28 |
# File 'lib/w3clove/page.rb', line 26 def valid? !errors.nil? && errors.empty? end |
#warnings ⇒ Object
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. && !w..empty?} .map do |w| W3Clove::Message.new(w., w.line, w., :warning) end rescue Exception => e @exception = e.to_s nil end |