Class: HTMLAcceptanceResult

Inherits:
Object
  • Object
show all
Defined in:
lib/html_acceptance/html_acceptance_result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options={})
  @resource = resource
  @html = html
  @exceptions = ''
  @datapath=datapath
  @tidyopts = options[:tidy_opts] || "-qi"
 @ignore_proprietary = options[:ignore_proprietary] 
  valid?
end

Instance Attribute Details

#exceptionsObject

Returns the value of attribute exceptions.



4
5
6
# File 'lib/html_acceptance/html_acceptance_result.rb', line 4

def exceptions
  @exceptions
end

#htmlObject

Returns the value of attribute html.



4
5
6
# File 'lib/html_acceptance/html_acceptance_result.rb', line 4

def html
  @html
end

#resourceObject

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.

Returns:

  • (Boolean)


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