Parent

Scrubyt::SharedUtils

Utilities shared between the other utility classes (XPathUtils, SimpleExampleLookup,...)

Constants

ENTITIES

Entities to replace - need to make this more complete, or install htmlentities or similar package

Public Class Methods

get_backtrace() click to toggle source
# File lib/scrubyt/utils/shared_utils.rb, line 48
def self.get_backtrace
  begin
    raise
  rescue Exception => ex
    backtrace = ex.backtrace
  end
  backtrace.slice!(0)
  backtrace
end
prepare_text_for_comparison(text) click to toggle source
# File lib/scrubyt/utils/shared_utils.rb, line 15
def self.prepare_text_for_comparison(text)
  unescape_entities text
  text.strip!
  text
end
traverse_for_match(node, regexp) click to toggle source

Entry point for finding the elements specified by examples

# File lib/scrubyt/utils/shared_utils.rb, line 28
def self.traverse_for_match(node, regexp)
  results = []
  traverse_for_match_inner = lambda { |node, regexp|
    ft = prepare_text_for_comparison(node.inner_html.gsub(/<.*?>/, ''))
    if ft =~ regexp
      node.instance_eval do
        @match_data = $~
        def match_data
          @match_data
        end
      end
      results << node
      results.delete node.parent if node.is_a? Hpricot::Elem
    end
    node.children.each { |child| traverse_for_match_inner.call(child, regexp) if (child.is_a? Hpricot::Elem) }
  }
  traverse_for_match_inner.call(node,regexp)
  results
end
unescape_entities(text) click to toggle source

Unescape the entities in the HTML!

# File lib/scrubyt/utils/shared_utils.rb, line 22
def self.unescape_entities(text)
  ENTITIES.each {|e,s| text.gsub!(/\&#{e};/) {"#{s}"} }
  text
end

Public Instance Methods

match_data() click to toggle source
# File lib/scrubyt/utils/shared_utils.rb, line 35
def match_data
  @match_data
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.