Class: HtmlKit::Document
- Inherits:
-
Object
- Object
- HtmlKit::Document
- Defined in:
- lib/html_kit/document.rb
Overview
HtmlKit::Document
Used for parsing urls which are ‘http` or `https` You can use this to validate a html document. This uses nokogiri internally. Warning: Currently doesn’t support HTML5 tags
For example (from irb):
irb(main):001:0> require 'html_kit'
=> true
irb(main):002:0> doc = HtmlKit::Document.new('http://www.nokogiri.org/index.html')
=> #<HtmlKit::Document:0x007fbb5408cfe8 @url="http://www.nokogiri.org/index.html">
irb(main):003:0> doc.valid?
=> false
Instance Method Summary collapse
- #errors ⇒ Object
- #html5? ⇒ Boolean
-
#initialize(url) ⇒ Document
constructor
A new instance of Document.
- #valid? ⇒ Boolean
Constructor Details
#initialize(url) ⇒ Document
Returns a new instance of Document.
27 28 29 30 31 |
# File 'lib/html_kit/document.rb', line 27 def initialize(url) @url = url.strip raise HtmlKit::Errors::InvalidUrlError unless supported_scheme? end |
Instance Method Details
#errors ⇒ Object
37 38 39 |
# File 'lib/html_kit/document.rb', line 37 def errors document.errors end |
#html5? ⇒ Boolean
41 42 43 |
# File 'lib/html_kit/document.rb', line 41 def html5? document.internal_subset.html5_dtd? end |
#valid? ⇒ Boolean
33 34 35 |
# File 'lib/html_kit/document.rb', line 33 def valid? errors.empty? end |