Class: Relevance::Tarantula::TidyHandler

Inherits:
Object
  • Object
show all
Includes:
Relevance::Tarantula
Defined in:
lib/relevance/tarantula/tidy_handler.rb

Instance Method Summary collapse

Methods included from Relevance::Tarantula

#log, #rails_root, #tarantula_home, #verbose

Constructor Details

#initialize(options = {}) ⇒ TidyHandler

Returns a new instance of TidyHandler.



14
15
16
# File 'lib/relevance/tarantula/tidy_handler.rb', line 14

def initialize(options = {})
  @options = {:show_warnings=>true}.merge(options)
end

Instance Method Details

#handle(result) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/relevance/tarantula/tidy_handler.rb', line 17

def handle(result)
  response = result.response
  return unless response.html?
  tidy = Tidy.open(@options) do |tidy|
    xml = tidy.clean(response.body)
    tidy
  end
  unless tidy.errors.blank?
    error_result = result.dup
    error_result.description = "Bad HTML (Tidy)"
    error_result.data = tidy.errors.inspect
    error_result
  end
end