Class: HTMLAcceptanceResult
- Inherits:
-
Object
- Object
- HTMLAcceptanceResult
- Defined in:
- lib/html_acceptance/html_acceptance_result.rb
Instance Attribute Summary collapse
-
#exceptions ⇒ Object
Returns the value of attribute exceptions.
-
#html ⇒ Object
Returns the value of attribute html.
-
#resource ⇒ Object
Returns the value of attribute resource.
Class Method Summary collapse
-
.load_from_files(filepath) ⇒ Object
takes a .url and loads the data into this object.
Instance Method Summary collapse
-
#accept! ⇒ Object
Saves the exception string for the given url or file path.
-
#initialize(resource, html, datapath, options = {}) ⇒ HTMLAcceptanceResult
constructor
valid options.
-
#valid? ⇒ Boolean
Validates an html string using html tidy.
Constructor Details
#initialize(resource, html, datapath, options = {}) ⇒ HTMLAcceptanceResult
valid options
7 8 9 10 11 12 13 14 15 |
# File 'lib/html_acceptance/html_acceptance_result.rb', line 7 def initialize(resource, html, datapath, ={}) @resource = resource @html = html @exceptions = '' @datapath=datapath @tidyopts = [:tidy_opts] || "-qi" @ignore_proprietary = [:ignore_proprietary] valid? end |
Instance Attribute Details
#exceptions ⇒ Object
Returns the value of attribute exceptions.
4 5 6 |
# File 'lib/html_acceptance/html_acceptance_result.rb', line 4 def exceptions @exceptions end |
#html ⇒ Object
Returns the value of attribute html.
4 5 6 |
# File 'lib/html_acceptance/html_acceptance_result.rb', line 4 def html @html end |
#resource ⇒ Object
Returns the value of attribute resource.
4 5 6 |
# File 'lib/html_acceptance/html_acceptance_result.rb', line 4 def resource @resource end |
Class Method Details
.load_from_files(filepath) ⇒ Object
takes a .url and loads the data into this object
18 19 20 21 22 |
# File 'lib/html_acceptance/html_acceptance_result.rb', line 18 def self.load_from_files(filepath) resource = File.open("#{filepath}.resource.txt", 'r').read html = File.open("#{filepath}.html.txt", 'r').read HTMLAcceptanceResult.new(resource, html, filepath) end |
Instance Method Details
#accept! ⇒ Object
Saves the exception string for the given url or file path. When next run, if the exception string is identical, valid? will return true. Note that #exceptions will still list the exception string, though, even if it is an accepted exception string.
40 41 42 |
# File 'lib/html_acceptance/html_acceptance_result.rb', line 40 def accept! File.open(data_path("accepted"), 'w') {|f| f.write(@exceptions) } end |
#valid? ⇒ Boolean
Validates an html string using html tidy. If there are no warnings or exceptions, or there is a previously accepted exception string that matches exactly, valid? returns true Line numbers of exceptions are likely to change with any edit, so our validation compares the exception strings with the lines and columns removed. Name can be a filename, file system path, or url, so long it is uniquely associated with the passed in html.
29 30 31 32 33 34 35 |
# File 'lib/html_acceptance/html_acceptance_result.rb', line 29 def valid? @exceptions = validate File.delete(data_path("accepted")) if File.exists?(data_path("accepted")) if @exceptions == '' valid = (filter(@exceptions) == '' or accepted?(@exceptions)) save_html_and_exceptions valid end |